示例#1
0
 /**
  * {@inheritDoc}
  */
 public function handle()
 {
     $this->setPageTitle("concrete5 has encountered an issue.");
     $result = self::QUIT;
     $enabled = Config::get('concrete.debug.display_errors');
     if ($enabled) {
         $detail = Config::get('concrete.debug.detail', 'message');
         if ($detail === 'debug') {
             $this->addDetails();
             $result = parent::handle();
         } else {
             $e = $this->getInspector()->getException();
             Core::make('helper/concrete/ui')->renderError(t('An unexpected error occurred.'), h($e->getMessage()));
         }
     } else {
         Core::make('helper/concrete/ui')->renderError(t('An unexpected error occurred.'), t('An error occurred while processing this request.'));
     }
     if (Config::get('concrete.log.errors')) {
         try {
             $e = $this->getInspector()->getException();
             $db = Database::get();
             if ($db->isConnected()) {
                 $l = new Logger(LOG_TYPE_EXCEPTIONS);
                 $l->emergency(sprintf("Exception Occurred: %s:%d %s (%d)\n", $e->getFile(), $e->getLine(), $e->getMessage(), $e->getCode()), array($e));
             }
         } catch (\Exception $e) {
         }
     }
     return $result;
 }
 /**
  * {@inheritDoc}
  */
 public function handle()
 {
     $this->setPageTitle("concrete5 has encountered an issue.");
     if (Config::get('concrete.log.errors')) {
         try {
             $e = $this->getInspector()->getException();
             $db = Database::get();
             if ($db->isConnected()) {
                 $l = new Logger(LOG_TYPE_EXCEPTIONS);
                 $l->emergency(t('Exception Occurred: ') . sprintf("%s:%d %s (%d)\n", $e->getFile(), $e->getLine(), $e->getMessage(), $e->getCode()), array($e));
             }
         } catch (Exception $e) {
         }
     }
     $debug = Config::get('concrete.debug.level', 0);
     if ($debug === DEBUG_DISPLAY_ERRORS) {
         $this->addDetails();
         return parent::handle();
     }
     Core::make('helper/concrete/ui')->renderError(t('An unexpected error occurred.'), t('An error occurred while processing this request.'));
     Core::shutdown();
 }
示例#3
0
 public function testOverringDefaultFunctionalityWithEvents()
 {
     $log = new Logger('emails');
     // should only have a database handler.
     $this->assertEquals(count($log->getHandlers()), 1);
     $this->assertEquals(count(Log::getHandlers()), 2);
     // this should still have the same stream handler from last test.
     $handler = new \Monolog\Handler\TestHandler(Logger::CRITICAL, false);
     $listener = Events::addListener('on_logger_create', function ($event) use($handler) {
         $logger = $event->getLogger();
         $formatter = new \Monolog\Formatter\LineFormatter();
         $handler->setFormatter($formatter);
         $logger->pushHandler($handler);
         return $logger;
     });
     $log2 = new Logger('transactions');
     $log3 = new Logger('testing');
     $this->assertEquals(count($log2->getHandlers()), 2);
     $this->assertEquals(count($log3->getHandlers()), 2);
     $log2->info('This is a test.');
     $log2->debug('This is a test.');
     $log3->debug('This is a test.');
     $log3->critical("oh boy this is big.");
     $log3->alert("Everything is broken.");
     $log3->emergency("Get out of bed.");
     $db = Database::get();
     $r = $db->GetAll('select * from Logs');
     $this->assertEquals(count($r), 3);
     // only the non-critical, non-alert, non-emergency items.
     $this->assertEquals(count($handler->getRecords()), 3);
     $records = $handler->getRecords();
     $this->assertEquals($records[0]['level'], Logger::CRITICAL);
     $this->assertEquals($records[1]['level'], Logger::ALERT);
     $this->assertEquals($records[2]['level'], Logger::EMERGENCY);
     $this->assertEquals($records[2]['message'], 'Get out of bed.');
     $listeners = Events::getListeners('on_logger_create');
     Events::removeListener('on_logger_create', $listeners[0]);
     // AND we pop the stream handler from the previous test
     Log::popHandler();
 }