예제 #1
0
 /**
  * Registers it self as error and exception handler.
  *
  * @static
  * @return void
  */
 public static function register()
 {
     switch (APPLICATION_ENV) {
         case Application::ENV_PRODUCTION:
         case Application::ENV_STAGING:
             ini_set('display_errors', 0);
             ini_set('display_startup_errors', 0);
             error_reporting(0);
             break;
         case Application::ENV_TEST:
         case Application::ENV_DEVELOPMENT:
             ini_set('display_errors', 1);
             ini_set('display_startup_errors', 1);
             error_reporting(~0);
             break;
         default:
             ini_set('display_errors', 0);
             ini_set('display_startup_errors', 0);
             error_reporting(0);
     }
     set_error_handler(function ($errno, $errstr, $errfile, $errline) {
         if (!($errno & error_reporting())) {
             return;
         }
         $options = array('type' => $errno, 'message' => $errstr, 'file' => $errfile, 'line' => $errline, 'isError' => true);
         Handler::handle(new Error($options));
     });
     set_exception_handler(function (\Exception $e) {
         $options = array('type' => $e->getCode(), 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'isException' => true, 'exception' => $e);
         Handler::handle(new Error($options));
     });
     register_shutdown_function(function () {
         if (!is_null($options = error_get_last())) {
             Handler::handle(new Error($options));
         }
     });
 }
예제 #2
0
파일: Bootstrap.php 프로젝트: huoybb/forum
 /**
  * Initialize the Logger.
  *
  * @param DiInterface   $di     Dependency Injector
  * @param Config        $config App config
  * @param EventsManager $em     Events Manager
  *
  * @return void
  */
 protected function initLogger(DiInterface $di, Config $config, EventsManager $em)
 {
     ErrorHandler::register();
     $di->set('logger', function ($filename = null, $format = null) use($config) {
         $format = $format ?: $config->get('logger')->format;
         $filename = trim($filename ?: $config->get('logger')->filename, '\\/');
         $path = rtrim($config->get('logger')->path, '\\/') . DIRECTORY_SEPARATOR;
         $formatter = new FormatterLine($format, $config->get('logger')->date);
         $logger = new FileLogger($path . $filename);
         $logger->setFormatter($formatter);
         $logger->setLogLevel($config->get('logger')->logLevel);
         return $logger;
     });
 }
예제 #3
0
 /**
  * Class constructor registers autoloading and error
  * handler.
  *
  * @param mixed $dependencyInjector
  * @return \Phalcon\Error\Application
  */
 public function __construct(DiInterface $dependencyInjector = null)
 {
     $this->registerAutoloaders();
     ErrorHandler::register();
     parent::__construct($dependencyInjector);
 }
 /**
  * Class constructor registers autoloading and error
  * handler.
  *
  * @return \Phalcon\Error\Application
  */
 public function __construct()
 {
     $this->registerAutoloaders();
     ErrorHandler::register();
 }
예제 #5
0
파일: Bootstrap.php 프로젝트: phalcon/forum
 /**
  * Initialize the Logger.
  */
 protected function initLogger()
 {
     ErrorHandler::register();
     $this->di->set('logger', function ($filename = null, $format = null) {
         /** @var DiInterface $this */
         $config = $this->getShared('config');
         $format = $format ?: $config->get('logger')->format;
         $filename = trim($filename ?: $config->get('logger')->filename, '\\/');
         $path = rtrim($config->get('logger')->path, '\\/') . DIRECTORY_SEPARATOR;
         if (false === strpos($filename, '.log')) {
             $filename = "{$filename}.log";
         }
         $formatter = new FormatterLine($format, $config->get('logger')->date);
         $logger = new FileLogger($path . $filename);
         $logger->setFormatter($formatter);
         $logger->setLogLevel($config->get('logger')->logLevel);
         return $logger;
     });
 }