From 4030c2a59c696b7b5c99b397669e9a65db1f7ffe Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 3 Jan 2018 16:05:06 -0600 Subject: [PATCH 01/16] first pass at multi-driver logging --- src/Illuminate/Contracts/Logging/Log.php | 19 - .../Foundation/Exceptions/Handler.php | 1 + src/Illuminate/Log/LogManager.php | 484 ++++++++++++++++++ src/Illuminate/Log/LogServiceProvider.php | 141 +---- src/Illuminate/Log/Writer.php | 138 +---- 5 files changed, 500 insertions(+), 283 deletions(-) create mode 100644 src/Illuminate/Log/LogManager.php diff --git a/src/Illuminate/Contracts/Logging/Log.php b/src/Illuminate/Contracts/Logging/Log.php index 5ecb9f8bdcf4..b30590d2c09b 100644 --- a/src/Illuminate/Contracts/Logging/Log.php +++ b/src/Illuminate/Contracts/Logging/Log.php @@ -76,23 +76,4 @@ public function debug($message, array $context = []); * @return void */ public function log($level, $message, array $context = []); - - /** - * Register a file log handler. - * - * @param string $path - * @param string $level - * @return void - */ - public function useFiles($path, $level = 'debug'); - - /** - * Register a daily file log handler. - * - * @param string $path - * @param int $days - * @param string $level - * @return void - */ - public function useDailyFiles($path, $days = 0, $level = 'debug'); } diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index f381382583c5..bce6e36287fa 100644 --- a/src/Illuminate/Foundation/Exceptions/Handler.php +++ b/src/Illuminate/Foundation/Exceptions/Handler.php @@ -94,6 +94,7 @@ public function __construct(Container $container) */ public function report(Exception $e) { + dd($e); if ($this->shouldntReport($e)) { return; } diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php new file mode 100644 index 000000000000..83a66c1dced1 --- /dev/null +++ b/src/Illuminate/Log/LogManager.php @@ -0,0 +1,484 @@ + Monolog::DEBUG, + 'info' => Monolog::INFO, + 'notice' => Monolog::NOTICE, + 'warning' => Monolog::WARNING, + 'error' => Monolog::ERROR, + 'critical' => Monolog::CRITICAL, + 'alert' => Monolog::ALERT, + 'emergency' => Monolog::EMERGENCY, + ]; + + /** + * Create a new Log manager instance. + * + * @param \Illuminate\Foundation\Application $app + * @return void + */ + public function __construct($app) + { + $this->app = $app; + } + + /** + * Get a log driver instance. + * + * @param string $driver + * @return mixed + */ + public function driver($driver = null) + { + return $this->get($driver); + } + + /** + * Attempt to get the log from the local cache. + * + * @param string $name + * @return \Psr\Log\LoggerInterface + */ + protected function get($name) + { + try { + return $this->stores[$name] ?? with($this->resolve($name), function ($monolog) { + return new Writer($monolog, $this->app['events']); + }); + } catch (Throwable $e) { + return tap($this->createEmergencyLogger(), function ($logger) use ($e) { + $logger->emergency('Unable to create configured logger. Using emergency logger.'); + + $logger->emergency($e); + }); + } + } + + /** + * Create an emergency log handler to avoid white screens of death. + * + * @return \Psr\Log\LoggerInterface + */ + protected function createEmergencyLogger() + { + return new Monolog('laravel', $this->prepareHandlers([], [new StreamHandler( + $this->app->storagePath().'/logs/laravel.log', $this->level(['level' => 'debug']) + )])); + } + + /** + * Resolve the given log instance by name. + * + * @param string $name + * @return \Psr\Log\LoggerInterface + * + * @throws \InvalidArgumentException + */ + protected function resolve($name) + { + $config = $this->getConfig($name); + + if (is_null($config)) { + throw new InvalidArgumentException("Log [{$name}] is not defined."); + } + + if (isset($this->customCreators[$config['driver']])) { + return $this->callCustomCreator($config); + } else { + $driverMethod = 'create'.ucfirst($config['driver']).'Driver'; + + if (method_exists($this, $driverMethod)) { + return $this->{$driverMethod}($config); + } else { + throw new InvalidArgumentException("Driver [{$config['driver']}] is not supported."); + } + } + } + + /** + * Call a custom driver creator. + * + * @param array $config + * @return mixed + */ + protected function callCustomCreator(array $config) + { + return $this->customCreators[$config['driver']]($this->app, $config); + } + + /** + * Create a custom log driver instance. + * + * @param array $config + * @return \Psr\Log\LoggerInterface + */ + protected function createCustomDriver(array $config) + { + return $this->app->make($config['factory'])->__invoke($config); + } + + /** + * Create an instance of the single file log driver. + * + * @param array $config + * @return \Psr\Log\LoggerInterface + */ + protected function createSingleDriver(array $config) + { + return new Monolog($this->channel($config), [ + $this->prepareHandler( + $config, new StreamHandler($config['path'], $this->level($config)) + ), + ]); + } + + /** + * Create an instance of the daily file log driver. + * + * @param array $config + * @return \Psr\Log\LoggerInterface + */ + protected function createDailyDriver(array $config) + { + return new Monolog($this->channel($config), [ + $this->prepareHandler($config, new RotatingFileHandler( + $config['path'], $config['days'] ?? 7, $this->level($config) + )), + ]); + } + + /** + * Create an instance of the syslog log driver. + * + * @param array $config + * @return \Psr\Log\LoggerInterface + */ + protected function createSyslogDriver(array $config) + { + return new Monolog($this->channel($config), [ + $this->prepareHandler($config, new SyslogHandler( + $this->app['config']['app.name'], $config['facility'] ?? LOG_USER, $this->level($config)) + ), + ]); + } + + /** + * Create an instance of the "error log" log driver. + * + * @param array $config + * @return \Psr\Log\LoggerInterface + */ + protected function createErrorlogDriver(array $config) + { + return new Monolog($this->channel($config), [ + $this->prepareHandler($config, new ErrorLogHandler( + $config['type'] ?? ErrorLogHandler::OPERATING_SYSTEM, $this->level($config)) + ), + ]); + } + + /** + * Prepare the handlers for usage by Monolog. + * + * @param array $config + * @param array $handlers + * @return \Monolog\Handler\HandlerInterface + */ + protected function prepareHandlers(array $config, array $handlers) + { + foreach ($handlers as $key => $handler) { + $handlers[$key] = $this->prepareHandler($config, $handler); + } + + return $handlers; + } + + /** + * Prepare the handler for usage by Monolog. + * + * @param array $config + * @param \Monolog\Handler\HandlerInterface $handler + * @return \Monolog\Handler\HandlerInterface + */ + protected function prepareHandler(array $config, HandlerInterface $handler) + { + return $handler->setFormatter($this->getDefaultFormatter($config)); + } + + /** + * Get a default Monolog formatter instance. + * + * @param array $config + * @return \Monolog\Formatter\LineFormatter + */ + protected function getDefaultFormatter(array $config) + { + return tap(new LineFormatter(null, null, true, true), function ($formatter) { + $formatter->includeStacktraces(); + }); + } + + /** + * Extract the log channel from the given configuration. + * + * @param array $config + * @return string + */ + protected function channel(array $config) + { + if (! isset($config['channel'])) { + return $this->app->bound('env') ? $this->app->environment() : 'production'; + } + + return $config['channel']; + } + + /** + * Parse the string level into a Monolog constant. + * + * @param array $config + * @return int + * + * @throws \InvalidArgumentException + */ + protected function level(array $config) + { + $level = $config['level'] ?? 'debug'; + + if (isset($this->levels[$level])) { + return $this->levels[$level]; + } + + throw new InvalidArgumentException('Invalid log level.'); + } + + /** + * Get the log connection configuration. + * + * @param string $name + * @return array + */ + protected function getConfig($name) + { + return $this->app['config']["logging.logs.{$name}"]; + } + + /** + * Get the default log driver name. + * + * @return string + */ + public function getDefaultDriver() + { + return $this->app['config']['logging.default']; + } + + /** + * Set the default log driver name. + * + * @param string $name + * @return void + */ + public function setDefaultDriver($name) + { + $this->app['config']['logging.default'] = $name; + } + + /** + * Register a custom driver creator Closure. + * + * @param string $driver + * @param \Closure $callback + * @return $this + */ + public function extend($driver, Closure $callback) + { + $this->customCreators[$driver] = $callback->bindTo($this, $this); + + return $this; + } + + /** + * System is unusable. + * + * @param string $message + * @param array $context + * + * @return void + */ + public function emergency($message, array $context = array()) + { + return $this->driver()->emergency($message, $context); + } + + /** + * Action must be taken immediately. + * + * Example: Entire website down, database unavailable, etc. This should + * trigger the SMS alerts and wake you up. + * + * @param string $message + * @param array $context + * + * @return void + */ + public function alert($message, array $context = array()) + { + return $this->driver()->alert($message, $context); + } + + /** + * Critical conditions. + * + * Example: Application component unavailable, unexpected exception. + * + * @param string $message + * @param array $context + * + * @return void + */ + public function critical($message, array $context = array()) + { + return $this->driver()->critical($message, $context); + } + + /** + * Runtime errors that do not require immediate action but should typically + * be logged and monitored. + * + * @param string $message + * @param array $context + * + * @return void + */ + public function error($message, array $context = array()) + { + return $this->driver()->error($message, $context); + } + + /** + * Exceptional occurrences that are not errors. + * + * Example: Use of deprecated APIs, poor use of an API, undesirable things + * that are not necessarily wrong. + * + * @param string $message + * @param array $context + * + * @return void + */ + public function warning($message, array $context = array()) + { + return $this->driver()->warning($message, $context); + } + + /** + * Normal but significant events. + * + * @param string $message + * @param array $context + * + * @return void + */ + public function notice($message, array $context = array()) + { + return $this->driver()->notice($message, $context); + } + + /** + * Interesting events. + * + * Example: User logs in, SQL logs. + * + * @param string $message + * @param array $context + * + * @return void + */ + public function info($message, array $context = array()) + { + return $this->driver()->info($message, $context); + } + + /** + * Detailed debug information. + * + * @param string $message + * @param array $context + * + * @return void + */ + public function debug($message, array $context = array()) + { + return $this->driver()->debug($message, $context); + } + + /** + * Logs with an arbitrary level. + * + * @param mixed $level + * @param string $message + * @param array $context + * + * @return void + */ + public function log($level, $message, array $context = array()) + { + return $this->driver()->log($message, $context); + } + + /** + * Dynamically call the default driver instance. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call($method, $parameters) + { + return $this->driver()->$method(...$parameters); + } +} diff --git a/src/Illuminate/Log/LogServiceProvider.php b/src/Illuminate/Log/LogServiceProvider.php index 306284d68a73..cd0739211932 100644 --- a/src/Illuminate/Log/LogServiceProvider.php +++ b/src/Illuminate/Log/LogServiceProvider.php @@ -2,7 +2,6 @@ namespace Illuminate\Log; -use Monolog\Logger as Monolog; use Illuminate\Support\ServiceProvider; class LogServiceProvider extends ServiceProvider @@ -15,145 +14,7 @@ class LogServiceProvider extends ServiceProvider public function register() { $this->app->singleton('log', function () { - return $this->createLogger(); + return new LogManager($this->app); }); } - - /** - * Create the logger. - * - * @return \Illuminate\Log\Writer - */ - public function createLogger() - { - $log = new Writer( - new Monolog($this->channel()), $this->app['events'] - ); - - if ($this->app->hasMonologConfigurator()) { - call_user_func($this->app->getMonologConfigurator(), $log->getMonolog()); - } else { - $this->configureHandler($log); - } - - return $log; - } - - /** - * Get the name of the log "channel". - * - * @return string - */ - protected function channel() - { - if ($this->app->bound('config') && - $channel = $this->app->make('config')->get('app.log_channel')) { - return $channel; - } - - return $this->app->bound('env') ? $this->app->environment() : 'production'; - } - - /** - * Configure the Monolog handlers for the application. - * - * @param \Illuminate\Log\Writer $log - * @return void - */ - protected function configureHandler(Writer $log) - { - $this->{'configure'.ucfirst($this->handler()).'Handler'}($log); - } - - /** - * Configure the Monolog handlers for the application. - * - * @param \Illuminate\Log\Writer $log - * @return void - */ - protected function configureSingleHandler(Writer $log) - { - $log->useFiles( - $this->app->storagePath().'/logs/laravel.log', - $this->logLevel() - ); - } - - /** - * Configure the Monolog handlers for the application. - * - * @param \Illuminate\Log\Writer $log - * @return void - */ - protected function configureDailyHandler(Writer $log) - { - $log->useDailyFiles( - $this->app->storagePath().'/logs/laravel.log', $this->maxFiles(), - $this->logLevel() - ); - } - - /** - * Configure the Monolog handlers for the application. - * - * @param \Illuminate\Log\Writer $log - * @return void - */ - protected function configureSyslogHandler(Writer $log) - { - $log->useSyslog($this->app->make('config')->get('app.name'), $this->logLevel()); - } - - /** - * Configure the Monolog handlers for the application. - * - * @param \Illuminate\Log\Writer $log - * @return void - */ - protected function configureErrorlogHandler(Writer $log) - { - $log->useErrorLog($this->logLevel()); - } - - /** - * Get the default log handler. - * - * @return string - */ - protected function handler() - { - if ($this->app->bound('config')) { - return $this->app->make('config')->get('app.log', 'single'); - } - - return 'single'; - } - - /** - * Get the log level for the application. - * - * @return string - */ - protected function logLevel() - { - if ($this->app->bound('config')) { - return $this->app->make('config')->get('app.log_level', 'debug'); - } - - return 'debug'; - } - - /** - * Get the maximum number of log files for the application. - * - * @return int - */ - protected function maxFiles() - { - if ($this->app->bound('config')) { - return $this->app->make('config')->get('app.log_max_files', 5); - } - - return 0; - } } diff --git a/src/Illuminate/Log/Writer.php b/src/Illuminate/Log/Writer.php index acf77b2dbd95..bc7c0dde40d6 100755 --- a/src/Illuminate/Log/Writer.php +++ b/src/Illuminate/Log/Writer.php @@ -4,28 +4,21 @@ use Closure; use RuntimeException; -use InvalidArgumentException; -use Monolog\Handler\StreamHandler; -use Monolog\Handler\SyslogHandler; -use Monolog\Formatter\LineFormatter; -use Monolog\Handler\ErrorLogHandler; -use Monolog\Logger as MonologLogger; +use Psr\Log\LoggerInterface; use Illuminate\Log\Events\MessageLogged; -use Monolog\Handler\RotatingFileHandler; use Illuminate\Contracts\Support\Jsonable; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Support\Arrayable; -use Psr\Log\LoggerInterface as PsrLoggerInterface; use Illuminate\Contracts\Logging\Log as LogContract; -class Writer implements LogContract, PsrLoggerInterface +class Writer implements LogContract, LoggerInterface { /** - * The Monolog logger instance. + * The logger implementation. * - * @var \Monolog\Logger + * @var \Psr\Log\LoggerInterface */ - protected $monolog; + protected $logger; /** * The event dispatcher instance. @@ -34,32 +27,16 @@ class Writer implements LogContract, PsrLoggerInterface */ protected $dispatcher; - /** - * The Log levels. - * - * @var array - */ - protected $levels = [ - 'debug' => MonologLogger::DEBUG, - 'info' => MonologLogger::INFO, - 'notice' => MonologLogger::NOTICE, - 'warning' => MonologLogger::WARNING, - 'error' => MonologLogger::ERROR, - 'critical' => MonologLogger::CRITICAL, - 'alert' => MonologLogger::ALERT, - 'emergency' => MonologLogger::EMERGENCY, - ]; - /** * Create a new log writer instance. * - * @param \Monolog\Logger $monolog + * @param \Psr\Log\LoggerInterface $logger * @param \Illuminate\Contracts\Events\Dispatcher|null $dispatcher * @return void */ - public function __construct(MonologLogger $monolog, Dispatcher $dispatcher = null) + public function __construct(LoggerInterface $logger, Dispatcher $dispatcher = null) { - $this->monolog = $monolog; + $this->logger = $logger; if (isset($dispatcher)) { $this->dispatcher = $dispatcher; @@ -189,7 +166,7 @@ public function write($level, $message, array $context = []) } /** - * Write a message to Monolog. + * Write a message to the log. * * @param string $level * @param string $message @@ -200,65 +177,7 @@ protected function writeLog($level, $message, $context) { $this->fireLogEvent($level, $message = $this->formatMessage($message), $context); - $this->monolog->{$level}($message, $context); - } - - /** - * Register a file log handler. - * - * @param string $path - * @param string $level - * @return void - */ - public function useFiles($path, $level = 'debug') - { - $this->monolog->pushHandler($handler = new StreamHandler($path, $this->parseLevel($level))); - - $handler->setFormatter($this->getDefaultFormatter()); - } - - /** - * Register a daily file log handler. - * - * @param string $path - * @param int $days - * @param string $level - * @return void - */ - public function useDailyFiles($path, $days = 0, $level = 'debug') - { - $this->monolog->pushHandler( - $handler = new RotatingFileHandler($path, $days, $this->parseLevel($level)) - ); - - $handler->setFormatter($this->getDefaultFormatter()); - } - - /** - * Register a Syslog handler. - * - * @param string $name - * @param string $level - * @param mixed $facility - * @return \Psr\Log\LoggerInterface - */ - public function useSyslog($name = 'laravel', $level = 'debug', $facility = LOG_USER) - { - return $this->monolog->pushHandler(new SyslogHandler($name, $facility, $level)); - } - - /** - * Register an error_log handler. - * - * @param string $level - * @param int $messageType - * @return void - */ - public function useErrorLog($level = 'debug', $messageType = ErrorLogHandler::OPERATING_SYSTEM) - { - $this->monolog->pushHandler( - new ErrorLogHandler($messageType, $this->parseLevel($level)) - ); + $this->logger->{$level}($message, $context); } /** @@ -316,42 +235,13 @@ protected function formatMessage($message) } /** - * Parse the string level into a Monolog constant. + * Get the underlying logger implementation. * - * @param string $level - * @return int - * - * @throws \InvalidArgumentException - */ - protected function parseLevel($level) - { - if (isset($this->levels[$level])) { - return $this->levels[$level]; - } - - throw new InvalidArgumentException('Invalid log level.'); - } - - /** - * Get the underlying Monolog instance. - * - * @return \Monolog\Logger - */ - public function getMonolog() - { - return $this->monolog; - } - - /** - * Get a default Monolog formatter instance. - * - * @return \Monolog\Formatter\LineFormatter + * @return \Psr\Log\LoggerInterface */ - protected function getDefaultFormatter() + public function getLogger() { - return tap(new LineFormatter(null, null, true, true), function ($formatter) { - $formatter->includeStacktraces(); - }); + return $this->logger; } /** From dafc8ae18871fc8f20b4ef0457bfb13a99fa86bc Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 3 Jan 2018 16:23:24 -0600 Subject: [PATCH 02/16] add helpers --- src/Illuminate/Foundation/helpers.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/helpers.php b/src/Illuminate/Foundation/helpers.php index ffb1ca53f6cc..088863c69c06 100644 --- a/src/Illuminate/Foundation/helpers.php +++ b/src/Illuminate/Foundation/helpers.php @@ -509,7 +509,7 @@ function info($message, $context = []) * * @param string $message * @param array $context - * @return \Illuminate\Contracts\Logging\Log|null + * @return \Illuminate\Log\LogManager|null */ function logger($message = null, array $context = []) { @@ -521,6 +521,19 @@ function logger($message = null, array $context = []) } } +if (! function_exists('logs')) { + /** + * Get a log driver instance. + * + * @param string $driver + * @return \Illuminate\Log\LogManager|\Psr\Log\LoggerInterface + */ + function logs($driver = null) + { + return $driver ? app('log')->driver($driver) : app('log'); + } +} + if (! function_exists('method_field')) { /** * Generate a form field to spoof the HTTP verb used by forms. From aff2dfba8f0375c72642055b0c3f1bef6abd867a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 3 Jan 2018 16:32:41 -0600 Subject: [PATCH 03/16] support custom formatter creation per channel --- src/Illuminate/Log/LogManager.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 83a66c1dced1..73f3e53e59a7 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -245,17 +245,21 @@ protected function prepareHandlers(array $config, array $handlers) */ protected function prepareHandler(array $config, HandlerInterface $handler) { - return $handler->setFormatter($this->getDefaultFormatter($config)); + return $handler->setFormatter($this->formatter($config)); } /** - * Get a default Monolog formatter instance. + * Get a Monolog formatter instance. * * @param array $config - * @return \Monolog\Formatter\LineFormatter + * @return \Monolog\Formatter\FormatterInterface */ - protected function getDefaultFormatter(array $config) + protected function formatter(array $config) { + if (isset($config['formatter'])) { + return $this->app->make($config['formatter'])->__invoke($config); + } + return tap(new LineFormatter(null, null, true, true), function ($formatter) { $formatter->includeStacktraces(); }); From 627cc8e5cc99de2d489d18e959564df2967fc74e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 3 Jan 2018 16:50:30 -0600 Subject: [PATCH 04/16] remove debug --- src/Illuminate/Foundation/Exceptions/Handler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index bce6e36287fa..f381382583c5 100644 --- a/src/Illuminate/Foundation/Exceptions/Handler.php +++ b/src/Illuminate/Foundation/Exceptions/Handler.php @@ -94,7 +94,6 @@ public function __construct(Container $container) */ public function report(Exception $e) { - dd($e); if ($this->shouldntReport($e)) { return; } From 849f0a148d6faaae072cd2c9f167faa688307b3a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Jan 2018 09:13:41 -0600 Subject: [PATCH 05/16] rename log writer to logger --- src/Illuminate/Foundation/Application.php | 2 +- src/Illuminate/Log/LogManager.php | 2 +- src/Illuminate/Log/{Writer.php => Logger.php} | 14 ++++++++- src/Illuminate/Support/Facades/Log.php | 2 +- tests/Log/LogWriterTest.php | 31 +++---------------- 5 files changed, 21 insertions(+), 30 deletions(-) rename src/Illuminate/Log/{Writer.php => Logger.php} (94%) diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index e1200161c009..f811be1270b3 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -1139,7 +1139,7 @@ public function registerCoreContainerAliases() 'filesystem.cloud' => [\Illuminate\Contracts\Filesystem\Cloud::class], 'hash' => [\Illuminate\Hashing\HashManager::class], 'translator' => [\Illuminate\Translation\Translator::class, \Illuminate\Contracts\Translation\Translator::class], - 'log' => [\Illuminate\Log\Writer::class, \Illuminate\Contracts\Logging\Log::class, \Psr\Log\LoggerInterface::class], + 'log' => [\Illuminate\Log\Logger::class, \Illuminate\Contracts\Logging\Log::class, \Psr\Log\LoggerInterface::class], 'mailer' => [\Illuminate\Mail\Mailer::class, \Illuminate\Contracts\Mail\Mailer::class, \Illuminate\Contracts\Mail\MailQueue::class], 'auth.password' => [\Illuminate\Auth\Passwords\PasswordBrokerManager::class, \Illuminate\Contracts\Auth\PasswordBrokerFactory::class], 'auth.password.broker' => [\Illuminate\Auth\Passwords\PasswordBroker::class, \Illuminate\Contracts\Auth\PasswordBroker::class], diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 73f3e53e59a7..1deadf6c71a2 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -86,7 +86,7 @@ protected function get($name) { try { return $this->stores[$name] ?? with($this->resolve($name), function ($monolog) { - return new Writer($monolog, $this->app['events']); + return new Logger($monolog, $this->app['events']); }); } catch (Throwable $e) { return tap($this->createEmergencyLogger(), function ($logger) use ($e) { diff --git a/src/Illuminate/Log/Writer.php b/src/Illuminate/Log/Logger.php similarity index 94% rename from src/Illuminate/Log/Writer.php rename to src/Illuminate/Log/Logger.php index bc7c0dde40d6..e4477e74049b 100755 --- a/src/Illuminate/Log/Writer.php +++ b/src/Illuminate/Log/Logger.php @@ -11,7 +11,7 @@ use Illuminate\Contracts\Support\Arrayable; use Illuminate\Contracts\Logging\Log as LogContract; -class Writer implements LogContract, LoggerInterface +class Logger implements LogContract, LoggerInterface { /** * The logger implementation. @@ -264,4 +264,16 @@ public function setEventDispatcher(Dispatcher $dispatcher) { $this->dispatcher = $dispatcher; } + + /** + * Dynamically proxy method calls to the underlying logger. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call($method, $parameters) + { + return $this->logger->{$method}(...$parameters); + } } diff --git a/src/Illuminate/Support/Facades/Log.php b/src/Illuminate/Support/Facades/Log.php index b10e064788c3..b28c6aca4c40 100755 --- a/src/Illuminate/Support/Facades/Log.php +++ b/src/Illuminate/Support/Facades/Log.php @@ -5,7 +5,7 @@ use Psr\Log\LoggerInterface; /** - * @see \Illuminate\Log\Writer + * @see \Illuminate\Log\Logger */ class Log extends Facade { diff --git a/tests/Log/LogWriterTest.php b/tests/Log/LogWriterTest.php index 8b649a37c933..bf7f7f38e18c 100755 --- a/tests/Log/LogWriterTest.php +++ b/tests/Log/LogWriterTest.php @@ -3,7 +3,7 @@ namespace Illuminate\Tests\Log; use Mockery as m; -use Illuminate\Log\Writer; +use Illuminate\Log\Logger; use PHPUnit\Framework\TestCase; class LogWriterTest extends TestCase @@ -13,30 +13,9 @@ public function tearDown() m::close(); } - public function testFileHandlerCanBeAdded() - { - $writer = new Writer($monolog = m::mock('Monolog\Logger')); - $monolog->shouldReceive('pushHandler')->once()->with(m::type('Monolog\Handler\StreamHandler')); - $writer->useFiles(__DIR__); - } - - public function testRotatingFileHandlerCanBeAdded() - { - $writer = new Writer($monolog = m::mock('Monolog\Logger')); - $monolog->shouldReceive('pushHandler')->once()->with(m::type('Monolog\Handler\RotatingFileHandler')); - $writer->useDailyFiles(__DIR__, 5); - } - - public function testErrorLogHandlerCanBeAdded() - { - $writer = new Writer($monolog = m::mock('Monolog\Logger')); - $monolog->shouldReceive('pushHandler')->once()->with(m::type('Monolog\Handler\ErrorLogHandler')); - $writer->useErrorLog(); - } - public function testMethodsPassErrorAdditionsToMonolog() { - $writer = new Writer($monolog = m::mock('Monolog\Logger')); + $writer = new Logger($monolog = m::mock('Monolog\Logger')); $monolog->shouldReceive('error')->once()->with('foo', []); $writer->error('foo'); @@ -44,7 +23,7 @@ public function testMethodsPassErrorAdditionsToMonolog() public function testWriterFiresEventsDispatcher() { - $writer = new Writer($monolog = m::mock('Monolog\Logger'), $events = new \Illuminate\Events\Dispatcher); + $writer = new Logger($monolog = m::mock('Monolog\Logger'), $events = new \Illuminate\Events\Dispatcher); $monolog->shouldReceive('error')->once()->with('foo', []); $events->listen(\Illuminate\Log\Events\MessageLogged::class, function ($event) { @@ -71,14 +50,14 @@ public function testWriterFiresEventsDispatcher() */ public function testListenShortcutFailsWithNoDispatcher() { - $writer = new Writer($monolog = m::mock('Monolog\Logger')); + $writer = new Logger($monolog = m::mock('Monolog\Logger')); $writer->listen(function () { }); } public function testListenShortcut() { - $writer = new Writer($monolog = m::mock('Monolog\Logger'), $events = m::mock('Illuminate\Contracts\Events\Dispatcher')); + $writer = new Logger($monolog = m::mock('Monolog\Logger'), $events = m::mock('Illuminate\Contracts\Events\Dispatcher')); $callback = function () { return 'success'; From ef8c7852fdc3e6ae484a276f4c94566ea8a7c0dc Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Jan 2018 10:10:02 -0600 Subject: [PATCH 06/16] support taps --- src/Illuminate/Log/LogManager.php | 34 +++++++++++++++++++++++++++++-- src/Illuminate/Log/Logger.php | 2 +- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 1deadf6c71a2..78a10e5e002d 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -4,6 +4,7 @@ use Closure; use Throwable; +use Illuminate\Support\Str; use Psr\Log\LoggerInterface; use InvalidArgumentException; use Monolog\Logger as Monolog; @@ -85,8 +86,8 @@ public function driver($driver = null) protected function get($name) { try { - return $this->stores[$name] ?? with($this->resolve($name), function ($monolog) { - return new Logger($monolog, $this->app['events']); + return $this->stores[$name] ?? with($this->resolve($name), function ($monolog) use ($name) { + return $this->tapInto($name, new Logger($monolog, $this->app['events'])); }); } catch (Throwable $e) { return tap($this->createEmergencyLogger(), function ($logger) use ($e) { @@ -97,6 +98,35 @@ protected function get($name) } } + /** + * Apply the configured taps for the logger. + * + * @param string $name + * @param \Illuminate\Log\Logger $logger + * @return \Illuminate\Log\Logger + */ + protected function tapInto($name, Logger $logger) + { + foreach ($this->getConfig($name)['tap'] ?? [] as $tap) { + list($class, $arguments) = $this->parseTap($tap); + + $this->app->make($class)->__invoke($logger, ...explode(',', $arguments)); + } + + return $logger; + } + + /** + * Parse the given tap class string into a class name and arguments string. + * + * @param string $tap + * @return array + */ + protected function parseTap($tap) + { + return Str::contains($tap, ':') ? explode(':', $tap, 2) : [$tap, '']; + } + /** * Create an emergency log handler to avoid white screens of death. * diff --git a/src/Illuminate/Log/Logger.php b/src/Illuminate/Log/Logger.php index e4477e74049b..fa77bab5320f 100755 --- a/src/Illuminate/Log/Logger.php +++ b/src/Illuminate/Log/Logger.php @@ -14,7 +14,7 @@ class Logger implements LogContract, LoggerInterface { /** - * The logger implementation. + * The underlying logger implementation. * * @var \Psr\Log\LoggerInterface */ From 3f545335743a45dcffe6738926908f2505e1f242 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Jan 2018 10:15:10 -0600 Subject: [PATCH 07/16] pipes can be used to customize formatter --- src/Illuminate/Log/LogManager.php | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 78a10e5e002d..61bfbaac0337 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -200,7 +200,7 @@ protected function createSingleDriver(array $config) { return new Monolog($this->channel($config), [ $this->prepareHandler( - $config, new StreamHandler($config['path'], $this->level($config)) + new StreamHandler($config['path'], $this->level($config)) ), ]); } @@ -214,7 +214,7 @@ protected function createSingleDriver(array $config) protected function createDailyDriver(array $config) { return new Monolog($this->channel($config), [ - $this->prepareHandler($config, new RotatingFileHandler( + $this->prepareHandler(new RotatingFileHandler( $config['path'], $config['days'] ?? 7, $this->level($config) )), ]); @@ -229,7 +229,7 @@ protected function createDailyDriver(array $config) protected function createSyslogDriver(array $config) { return new Monolog($this->channel($config), [ - $this->prepareHandler($config, new SyslogHandler( + $this->prepareHandler(new SyslogHandler( $this->app['config']['app.name'], $config['facility'] ?? LOG_USER, $this->level($config)) ), ]); @@ -244,7 +244,7 @@ protected function createSyslogDriver(array $config) protected function createErrorlogDriver(array $config) { return new Monolog($this->channel($config), [ - $this->prepareHandler($config, new ErrorLogHandler( + $this->prepareHandler(new ErrorLogHandler( $config['type'] ?? ErrorLogHandler::OPERATING_SYSTEM, $this->level($config)) ), ]); @@ -253,14 +253,13 @@ protected function createErrorlogDriver(array $config) /** * Prepare the handlers for usage by Monolog. * - * @param array $config * @param array $handlers * @return \Monolog\Handler\HandlerInterface */ - protected function prepareHandlers(array $config, array $handlers) + protected function prepareHandlers(array $handlers) { foreach ($handlers as $key => $handler) { - $handlers[$key] = $this->prepareHandler($config, $handler); + $handlers[$key] = $this->prepareHandler($handler); } return $handlers; @@ -269,27 +268,21 @@ protected function prepareHandlers(array $config, array $handlers) /** * Prepare the handler for usage by Monolog. * - * @param array $config * @param \Monolog\Handler\HandlerInterface $handler * @return \Monolog\Handler\HandlerInterface */ - protected function prepareHandler(array $config, HandlerInterface $handler) + protected function prepareHandler(HandlerInterface $handler) { - return $handler->setFormatter($this->formatter($config)); + return $handler->setFormatter($this->formatter()); } /** * Get a Monolog formatter instance. * - * @param array $config * @return \Monolog\Formatter\FormatterInterface */ - protected function formatter(array $config) + protected function formatter() { - if (isset($config['formatter'])) { - return $this->app->make($config['formatter'])->__invoke($config); - } - return tap(new LineFormatter(null, null, true, true), function ($formatter) { $formatter->includeStacktraces(); }); From 7f9a879491b26aa665e29e2aeac04675a8a0391d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Jan 2018 10:17:36 -0600 Subject: [PATCH 08/16] rename method --- src/Illuminate/Log/LogManager.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 61bfbaac0337..c3df1ed550ad 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -87,7 +87,7 @@ protected function get($name) { try { return $this->stores[$name] ?? with($this->resolve($name), function ($monolog) use ($name) { - return $this->tapInto($name, new Logger($monolog, $this->app['events'])); + return $this->tap($name, new Logger($monolog, $this->app['events'])); }); } catch (Throwable $e) { return tap($this->createEmergencyLogger(), function ($logger) use ($e) { @@ -105,9 +105,9 @@ protected function get($name) * @param \Illuminate\Log\Logger $logger * @return \Illuminate\Log\Logger */ - protected function tapInto($name, Logger $logger) + protected function tap($name, Logger $logger) { - foreach ($this->getConfig($name)['tap'] ?? [] as $tap) { + foreach ($this->configurationFor($name)['tap'] ?? [] as $tap) { list($class, $arguments) = $this->parseTap($tap); $this->app->make($class)->__invoke($logger, ...explode(',', $arguments)); @@ -149,7 +149,7 @@ protected function createEmergencyLogger() */ protected function resolve($name) { - $config = $this->getConfig($name); + $config = $this->configurationFor($name); if (is_null($config)) { throw new InvalidArgumentException("Log [{$name}] is not defined."); @@ -328,7 +328,7 @@ protected function level(array $config) * @param string $name * @return array */ - protected function getConfig($name) + protected function configurationFor($name) { return $this->app['config']["logging.logs.{$name}"]; } From cb6425fc8bc97709fa401938f550d00ddf96b8b2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Jan 2018 10:26:09 -0600 Subject: [PATCH 09/16] change array key --- src/Illuminate/Log/LogManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index c3df1ed550ad..ba0046a4c3ba 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -187,7 +187,7 @@ protected function callCustomCreator(array $config) */ protected function createCustomDriver(array $config) { - return $this->app->make($config['factory'])->__invoke($config); + return $this->app->make($config['via'])->__invoke($config); } /** From 22b4229a1d535da50732b43978eba571c9e10d72 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Jan 2018 11:29:36 -0600 Subject: [PATCH 10/16] remove interface --- src/Illuminate/Contracts/Logging/Log.php | 79 ------------------------ src/Illuminate/Log/LogManager.php | 9 ++- src/Illuminate/Log/Logger.php | 3 +- 3 files changed, 5 insertions(+), 86 deletions(-) delete mode 100644 src/Illuminate/Contracts/Logging/Log.php diff --git a/src/Illuminate/Contracts/Logging/Log.php b/src/Illuminate/Contracts/Logging/Log.php deleted file mode 100644 index b30590d2c09b..000000000000 --- a/src/Illuminate/Contracts/Logging/Log.php +++ /dev/null @@ -1,79 +0,0 @@ -get($driver); + return $this->get($driver ?? $this->getDefaultDriver()); } /** @@ -134,9 +133,9 @@ protected function parseTap($tap) */ protected function createEmergencyLogger() { - return new Monolog('laravel', $this->prepareHandlers([], [new StreamHandler( + return new Logger(new Monolog('laravel', $this->prepareHandlers([], [new StreamHandler( $this->app->storagePath().'/logs/laravel.log', $this->level(['level' => 'debug']) - )])); + )])), $this->app['events']); } /** diff --git a/src/Illuminate/Log/Logger.php b/src/Illuminate/Log/Logger.php index fa77bab5320f..e2010846c85b 100755 --- a/src/Illuminate/Log/Logger.php +++ b/src/Illuminate/Log/Logger.php @@ -9,9 +9,8 @@ use Illuminate\Contracts\Support\Jsonable; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Support\Arrayable; -use Illuminate\Contracts\Logging\Log as LogContract; -class Logger implements LogContract, LoggerInterface +class Logger implements LoggerInterface { /** * The underlying logger implementation. From 9b073cbf31b941923f1824c10cd75074eefdae93 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Jan 2018 11:30:46 -0600 Subject: [PATCH 11/16] fix call to prepare handlers --- src/Illuminate/Log/LogManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 09948cbe7099..d4e56d4e6022 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -133,7 +133,7 @@ protected function parseTap($tap) */ protected function createEmergencyLogger() { - return new Logger(new Monolog('laravel', $this->prepareHandlers([], [new StreamHandler( + return new Logger(new Monolog('laravel', $this->prepareHandlers([new StreamHandler( $this->app->storagePath().'/logs/laravel.log', $this->level(['level' => 'debug']) )])), $this->app['events']); } From f2c95cd3fc8313ffff8710b3b06de42eb1f0b65c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Jan 2018 11:45:04 -0600 Subject: [PATCH 12/16] allow watching log messages --- src/Illuminate/Log/LogManager.php | 42 +++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index d4e56d4e6022..4b4c173c01f4 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -13,6 +13,7 @@ use Monolog\Formatter\LineFormatter; use Monolog\Handler\ErrorLogHandler; use Monolog\Handler\HandlerInterface; +use Illuminate\Log\Events\MessageLogged; use Monolog\Handler\RotatingFileHandler; class LogManager implements LoggerInterface @@ -65,6 +66,17 @@ public function __construct($app) $this->app = $app; } + /** + * Get a log channel instance. + * + * @param string $driver + * @return mixed + */ + public function channel($channel = null) + { + return $this->driver($channel); + } + /** * Get a log driver instance. * @@ -197,7 +209,7 @@ protected function createCustomDriver(array $config) */ protected function createSingleDriver(array $config) { - return new Monolog($this->channel($config), [ + return new Monolog($this->parseChannel($config), [ $this->prepareHandler( new StreamHandler($config['path'], $this->level($config)) ), @@ -212,7 +224,7 @@ protected function createSingleDriver(array $config) */ protected function createDailyDriver(array $config) { - return new Monolog($this->channel($config), [ + return new Monolog($this->parseChannel($config), [ $this->prepareHandler(new RotatingFileHandler( $config['path'], $config['days'] ?? 7, $this->level($config) )), @@ -227,7 +239,7 @@ protected function createDailyDriver(array $config) */ protected function createSyslogDriver(array $config) { - return new Monolog($this->channel($config), [ + return new Monolog($this->parseChannel($config), [ $this->prepareHandler(new SyslogHandler( $this->app['config']['app.name'], $config['facility'] ?? LOG_USER, $this->level($config)) ), @@ -242,7 +254,7 @@ protected function createSyslogDriver(array $config) */ protected function createErrorlogDriver(array $config) { - return new Monolog($this->channel($config), [ + return new Monolog($this->parseChannel($config), [ $this->prepareHandler(new ErrorLogHandler( $config['type'] ?? ErrorLogHandler::OPERATING_SYSTEM, $this->level($config)) ), @@ -287,13 +299,33 @@ protected function formatter() }); } + /** + * Monitor log messages and execute a callback if a message matches a given truth test. + * + * @param callable|string $watcher + * @param callable $callback + * @return void + */ + public function watch($watcher, $callback) + { + $watcher = is_callable($watcher) ? $watcher : function ($level, $message) use ($watcher) { + return Str::is($watcher, $message); + }; + + $this->app['events']->listen(MessageLogged::class, function ($event) use ($watcher, $callback) { + if ($watcher($event->level, $event->message, $event->context)) { + $callback($event->level, $event->message, $event->context); + } + }); + } + /** * Extract the log channel from the given configuration. * * @param array $config * @return string */ - protected function channel(array $config) + protected function parseChannel(array $config) { if (! isset($config['channel'])) { return $this->app->bound('env') ? $this->app->environment() : 'production'; From 549e162eb2046ca5158f272b1bfe0af7a2e7f873 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Jan 2018 12:19:52 -0600 Subject: [PATCH 13/16] channels --- src/Illuminate/Log/LogManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 4b4c173c01f4..74989560cd1c 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -361,7 +361,7 @@ protected function level(array $config) */ protected function configurationFor($name) { - return $this->app['config']["logging.logs.{$name}"]; + return $this->app['config']["logging.channels.{$name}"]; } /** From db4c6907e267a5ba9897bc90e0fcac75ff894d2c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Jan 2018 12:21:32 -0600 Subject: [PATCH 14/16] Apply fixes from StyleCI (#22634) --- src/Illuminate/Log/LogManager.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 74989560cd1c..b2c8d83a3ba6 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -407,7 +407,7 @@ public function extend($driver, Closure $callback) * * @return void */ - public function emergency($message, array $context = array()) + public function emergency($message, array $context = []) { return $this->driver()->emergency($message, $context); } @@ -423,7 +423,7 @@ public function emergency($message, array $context = array()) * * @return void */ - public function alert($message, array $context = array()) + public function alert($message, array $context = []) { return $this->driver()->alert($message, $context); } @@ -438,7 +438,7 @@ public function alert($message, array $context = array()) * * @return void */ - public function critical($message, array $context = array()) + public function critical($message, array $context = []) { return $this->driver()->critical($message, $context); } @@ -452,7 +452,7 @@ public function critical($message, array $context = array()) * * @return void */ - public function error($message, array $context = array()) + public function error($message, array $context = []) { return $this->driver()->error($message, $context); } @@ -468,7 +468,7 @@ public function error($message, array $context = array()) * * @return void */ - public function warning($message, array $context = array()) + public function warning($message, array $context = []) { return $this->driver()->warning($message, $context); } @@ -481,7 +481,7 @@ public function warning($message, array $context = array()) * * @return void */ - public function notice($message, array $context = array()) + public function notice($message, array $context = []) { return $this->driver()->notice($message, $context); } @@ -496,7 +496,7 @@ public function notice($message, array $context = array()) * * @return void */ - public function info($message, array $context = array()) + public function info($message, array $context = []) { return $this->driver()->info($message, $context); } @@ -509,7 +509,7 @@ public function info($message, array $context = array()) * * @return void */ - public function debug($message, array $context = array()) + public function debug($message, array $context = []) { return $this->driver()->debug($message, $context); } @@ -523,7 +523,7 @@ public function debug($message, array $context = array()) * * @return void */ - public function log($level, $message, array $context = array()) + public function log($level, $message, array $context = []) { return $this->driver()->log($message, $context); } From a9fa1bf91aa59da0ffb87cf112869a40803edc5b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Jan 2018 14:26:12 -0600 Subject: [PATCH 15/16] tweaks from feedback --- src/Illuminate/Log/LogManager.php | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 74989560cd1c..cb5df81abe9f 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -102,9 +102,9 @@ protected function get($name) }); } catch (Throwable $e) { return tap($this->createEmergencyLogger(), function ($logger) use ($e) { - $logger->emergency('Unable to create configured logger. Using emergency logger.'); - - $logger->emergency($e); + $logger->emergency('Unable to create configured logger. Using emergency logger.', [ + 'exception' => $e, + ]); }); } } @@ -299,26 +299,6 @@ protected function formatter() }); } - /** - * Monitor log messages and execute a callback if a message matches a given truth test. - * - * @param callable|string $watcher - * @param callable $callback - * @return void - */ - public function watch($watcher, $callback) - { - $watcher = is_callable($watcher) ? $watcher : function ($level, $message) use ($watcher) { - return Str::is($watcher, $message); - }; - - $this->app['events']->listen(MessageLogged::class, function ($event) use ($watcher, $callback) { - if ($watcher($event->level, $event->message, $event->context)) { - $callback($event->level, $event->message, $event->context); - } - }); - } - /** * Extract the log channel from the given configuration. * From 897c87f2f6bba03669918329b5c824cc1e8a3f1f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Jan 2018 14:38:17 -0600 Subject: [PATCH 16/16] Apply fixes from StyleCI (#22637) --- src/Illuminate/Log/LogManager.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 439dfc8ee949..f3011b81e097 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -13,7 +13,6 @@ use Monolog\Formatter\LineFormatter; use Monolog\Handler\ErrorLogHandler; use Monolog\Handler\HandlerInterface; -use Illuminate\Log\Events\MessageLogged; use Monolog\Handler\RotatingFileHandler; class LogManager implements LoggerInterface