protected function setLogger(&$c) { $c['Logger'] = function () { $log = new Logger('ErrorLogger'); $handler = new ErrorLogHandler(); $formatter = new LineFormatter(); $formatter->includeStacktraces(); $handler->setFormatter($formatter); $log->pushHandler($handler); return $log; }; }
/** * Set up test environment. */ public function setUp() { parent::setUp(); $this->link = new \MySQLi('localhost', 'root', ''); if ($this->link->connect_error) { throw new \RuntimeException('Failed to connect to database. MySQL said: ' . $this->link->connect_error); } if (!$this->link->select_db('activecollab_jobs_queue_test')) { throw new \RuntimeException('Failed to select database.'); } $this->connection = new MysqliConnection($this->link); $this->queue = new MySqlQueue($this->connection); $this->dispatcher = new Dispatcher($this->queue); $this->log_file_path = dirname(__DIR__) . '/logs/' . date('Y-m-d') . '.txt'; if (is_file($this->log_file_path)) { unlink($this->log_file_path); } $this->log = new Logger('cli'); $handler = new StreamHandler($this->log_file_path, Logger::DEBUG); $formatter = new LineFormatter(); $formatter->includeStacktraces(true); $handler->setFormatter($formatter); $this->log->pushHandler($handler); $this->container = new Container(['dispatcher' => $this->dispatcher, 'log' => $this->log]); }
/** * @param array $formatterConfig * * @return Monolog\Formatter\LineFormatter */ private function _createLine(array $formatterConfig) { $boolValues = array('true' => true, 'false' => false); $format = null; if (true === array_key_exists('format', $formatterConfig)) { $format = $formatterConfig['format']; } $dateFormat = null; if (true === array_key_exists('dateFormat', $formatterConfig)) { $dateFormat = $formatterConfig['dateFormat']; } $includeStacktraces = false; if (true === array_key_exists('includeStacktraces', $formatterConfig) && true === array_key_exists($formatterConfig['includeStacktraces'], $boolValues)) { $includeStacktraces = $boolValues[$formatterConfig['includeStacktraces']]; } $allowInlineLineBreaks = false; if (true === array_key_exists('allowInlineLineBreaks', $formatterConfig) && true === array_key_exists($formatterConfig['allowInlineLineBreaks'], $boolValues)) { $allowInlineLineBreaks = $boolValues[$formatterConfig['allowInlineLineBreaks']]; } $ignoreEmptyContextAndExtra = false; if (true === array_key_exists('ignoreEmptyContextAndExtra', $formatterConfig) && true === array_key_exists($formatterConfig['ignoreEmptyContextAndExtra'], $boolValues)) { $ignoreEmptyContextAndExtra = $boolValues[$formatterConfig['ignoreEmptyContextAndExtra']]; } $formatter = new Monolog\Formatter\LineFormatter($format, $dateFormat); $formatter->includeStacktraces($includeStacktraces); $formatter->allowInlineLineBreaks($allowInlineLineBreaks); $formatter->ignoreEmptyContextAndExtra($ignoreEmptyContextAndExtra); return $formatter; }
use TimeManager\Transformer\Task as TaskTransformer; use TimeManager\Util\Date; $container = $app->getContainer(); $container['errorHandler'] = function ($container) { return [$container->get(ErrorController::class), 'errorAction']; }; $container['notFoundHandler'] = function ($container) { return [$container->get(ErrorController::class), 'notFoundAction']; }; $container['notAllowedHandler'] = function ($container) { return [$container->get(ErrorController::class), 'notAllowedAction']; }; $container['logger'] = function ($container) { $settings = $container->get('settings'); $formatter = new LineFormatter(); $formatter->includeStacktraces(); $handler = new StreamHandler($settings['logger']['path'], Logger::DEBUG); $handler->setFormatter($formatter); $logger = new Logger($settings['logger']['name']); $logger->pushProcessor(new WebProcessor()); $logger->pushHandler($handler); return $logger; }; $container[ErrorController::class] = function ($container) { return new ErrorController($container->get(InfoPresenter::class), $container->get('response'), $container->get('logger')); }; $container[TaskController::class] = function ($container) { return new TaskController($container->get(DataPresenter::class), $container->get(InfoPresenter::class), $container->get(TaskService::class), $container->get(TaskTransformer::class)); }; $container[EntityManager::class] = function ($container) { $config = $container->get('settings')['database'];