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; }; }
/** * @covers Monolog\Handler\ErrorLogHandler::write */ public function testShouldLogMessagesUsingErrorLogFuncion() { $type = ErrorLogHandler::OPERATING_SYSTEM; $handler = new ErrorLogHandler($type); $handler->handle($this->getRecord(Logger::ERROR)); $this->assertStringMatchesFormat('[%s] test.ERROR: test [] []', $GLOBALS['error_log'][0]); $this->assertSame($GLOBALS['error_log'][1], $type); }
/** * @covers Monolog\Handler\ErrorLogHandler::write */ public function testShouldLogMessagesUsingErrorLogFuncion() { $type = ErrorLogHandler::OPERATING_SYSTEM; $handler = new ErrorLogHandler($type); $handler->setFormatter(new LineFormatter('%channel%.%level_name%: %message% %context% %extra%', null, true)); $handler->handle($this->getRecord(Logger::ERROR, "Foo\nBar\r\n\r\nBaz")); $this->assertSame("test.ERROR: Foo\nBar\r\n\r\nBaz [] []", $GLOBALS['error_log'][0][0]); $this->assertSame($GLOBALS['error_log'][0][1], $type); $handler = new ErrorLogHandler($type, Logger::DEBUG, true, true); $handler->setFormatter(new LineFormatter(null, null, true)); $handler->handle($this->getRecord(Logger::ERROR, "Foo\nBar\r\n\r\nBaz")); $this->assertStringMatchesFormat('[%s] test.ERROR: Foo', $GLOBALS['error_log'][1][0]); $this->assertSame($GLOBALS['error_log'][1][1], $type); $this->assertStringMatchesFormat('Bar', $GLOBALS['error_log'][2][0]); $this->assertSame($GLOBALS['error_log'][2][1], $type); $this->assertStringMatchesFormat('Baz [] []', $GLOBALS['error_log'][3][0]); $this->assertSame($GLOBALS['error_log'][3][1], $type); }
public function handle(array $record) { if ($record['channel'] === $this->appName) { $this->setFormatter($this->defaultFormatter); $record['filename'] = strtolower($record['level_name']); } else { $this->setFormatter($this->priorityFormatter); $record['filename'] = $record['channel']; } return parent::handle($record); }
public function setLevel($level) { if (!is_string($level)) { parent::setLevel((int) $level); return; } if (!defined('\\Monolog\\Logger::' . $level)) { return; } parent::setLevel(constant('\\Monolog\\Logger::' . $level)); }
public function register(Container $app) { $app['logger'] = function () use($app) { return $app['monolog']; }; $app['monolog'] = function ($app) { $logger = new Logger($app['monolog.name']); $rotate = $app['config']->get('app.log.rotate', 'single'); $logger->pushHandler($app['monolog.handler.' . $rotate]); return $logger; }; $app['monolog.formatter'] = function () { return new LineFormatter(); }; $app['monolog.handler.single'] = function ($app) { $handler = new StreamHandler($app['monolog.logfile'], $app['monolog.level']); $handler->setFormatter($app['monolog.formatter']); return $handler; }; $app['monolog.handler.daily'] = function ($app) { $maxFiles = $app['config']->get('app.log.max_files', 5); $handler = new RotatingFileHandler($app['monolog.logfile'], $maxFiles, $app['monolog.level']); $handler->setFormatter($app['monolog.formatter']); return $handler; }; $app['monolog.handler.error'] = function ($app) { $handler = new ErrorLogHandler(ErrorLogHandler::OPERATING_SYSTEM, $app['monolog.level']); $handler->setFormatter($app['monolog.formatter']); return $handler; }; $app['monolog.handler.syslog'] = function ($app) { $handler = new SyslogHandler($app['monolog.name'], LOG_USER, $app['monolog.level']); $handler->setFormatter($app['monolog.formatter']); return $handler; }; $level = $app['config']->get('app.log.level', 'debug'); $app['monolog.level'] = $this->parseLevel($level); $app['monolog.logfile'] = $app['path.logs'] . $this->getSettings('app.log.logfile'); $app['monolog.name'] = $this->getSettings('monolog.name', 'app.name'); }
public function useErrorLog($level = 'debug', $messageType = ErrorLogHandler::OPERATING_SYSTEM) { $level = $this->parseLevel($level); $this->monolog->pushHandler($handler = new ErrorLogHandler($messageType, $level)); $handler->setFormatter($this->getDefaultFormatter()); }
* You are free to copy this file as "loghandler.php" and make any * modification you need. This allows you to make customization that will not * be overwritten during an update. * * WHMCS will attempt to load your custom "loghandler.php" instead of this * file ("dist.loghandler.php"). * **************************** ** DO NOT EDIT THIS FILE! ** **************************** * * The WHMCS initializes a Monolog logger, exposing the handler for customization. * * You are free to customize the handlers by modify this file to your needs. * * By default, WHMCS will log all messages to the configured PHP error log * (i.e., the Apache webserver error log). * * NOTE: * * The applications handler by default, as defined here, will log at the * 'warning' level, if most verbose is required, consider 'info' or 'debug' * * Please see Monolog documentation for usage of handlers and log levels * @link https://github.com/Seldaek/monolog */ if (!defined("ROOTDIR")) { die("This file cannot be accessed directly"); } $handle = new ErrorLogHandler(ErrorLogHandler::OPERATING_SYSTEM, Logger::WARNING); $handle->setFormatter(new LineFormatter('[%channel%] %level_name%: %message% %context% %extra%')); Log::pushHandler($handle);
/** * @return \Psr\Log\LoggerInterface */ public function getLogger() { $handler = new MonologHandler\ErrorLogHandler(MonologHandler\ErrorLogHandler::OPERATING_SYSTEM, Logger::ERROR, true, true); $handler->setFormatter(new ErrorFormatter()); $logger = new Logger('psx'); $logger->pushHandler($handler); return $logger; }
public function build(ContainerBuilder $builder) { $builder->bind(LoggerInterface::class)->scoped(new Singleton())->to(function (TestSystem $system) { $handler = new ErrorLogHandler(ErrorLogHandler::SAPI, Logger::toMonologLevel(strtolower($system->getLogLevel()))); $handler->pushProcessor(new PsrLogMessageProcessor()); $monolog = new Logger('System'); $monolog->pushHandler($handler); return $monolog; }); }