示例#1
0
 public function testLogReport()
 {
     $logReport = Logger::report('', TRUE);
     $this->assertCount(1, $logReport);
     Logger::report('/tmp/juriya_log.txt');
 }
示例#2
0
 /**
  * Exception handler
  *
  * @return string Exception description
  */
 public function handleException()
 {
     $severity = $this->severity($this->exception->getCode());
     $message = $this->message($this->exception->getMessage(), $this->exception->getFile(), $this->exception->getLine());
     Logger::write('Juriya\\Juriya', $message, 3);
     echo Debugger::trace($severity, $message, $this->exception->getTrace());
 }
示例#3
0
 /**
  * Handle main environment setter
  * 
  * @param  string environment
  * @throws object InvalidArgumentException
  */
 public function setEnvironment($state = '')
 {
     if (!in_array($state, array('production', 'development', 'test'))) {
         throw new \RangeException(I18n::translate('invalid_environment_state'));
     }
     // Define environment state
     defined('ENVIRONMENT') or define('ENVIRONMENT', $state);
     // Adjust the error reporting and display levels for each environment.
     // @codeCoverageIgnoreStart
     if (ENVIRONMENT == 'production') {
         error_reporting(0);
     } else {
         error_reporting(E_ALL | E_STRICT);
     }
     // @codeCoverageIgnoreEnd
     // Turn off any errors reports.
     ini_set('display_errors', 'Off');
     // Limit maximum execution time
     set_time_limit(300);
     // Register exception and error handler
     set_exception_handler(function ($e) {
         \Juriya\Exception::factory($e)->handleException();
     });
     set_error_handler(function ($errno, $errstr, $errfile, $errline) {
         $e = array($errno, $errstr, $errfile, $errline);
         \Juriya\Exception::factory($e)->handleError();
     });
     // Register shutdown handler
     // @codeCoverageIgnoreStart
     register_shutdown_function(function () {
         // Find some premature script error
         $lasterror = error_get_last();
         if (!empty($lasterror)) {
             \Juriya\Exception::factory(array_values($lasterror))->handleError();
         }
         // Generate log reports
         ENVIRONMENT == 'test' or \Juriya\Logger::report();
     });
     // @codeCoverageIgnoreEnd
 }