diff --git a/src/Illuminate/Log/Events/MessageLogged.php b/src/Illuminate/Log/Events/MessageLogged.php new file mode 100644 index 000000000000..312b343a356d --- /dev/null +++ b/src/Illuminate/Log/Events/MessageLogged.php @@ -0,0 +1,42 @@ +level = $level; + $this->message = $message; + $this->context = $context; + } +} diff --git a/src/Illuminate/Log/LogServiceProvider.php b/src/Illuminate/Log/LogServiceProvider.php index 65a5f9670ca5..ceb978995264 100644 --- a/src/Illuminate/Log/LogServiceProvider.php +++ b/src/Illuminate/Log/LogServiceProvider.php @@ -27,37 +27,37 @@ public function register() public function createLogger() { $log = new Writer( - new Monolog($this->app->bound('env') ? $this->app->environment() : 'production'), $this->app['events'] + new Monolog($this->channel()), $this->app['events'] ); if ($this->app->hasMonologConfigurator()) { - call_user_func( - $this->app->getMonologConfigurator(), $log->getMonolog() - ); + call_user_func($this->app->getMonologConfigurator(), $log->getMonolog()); } else { - $this->configureHandlers($log); + $this->configureHandler($log); } return $log; } + /** + * Get the name of the log "channel". + * + * @return string + */ + protected function 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 configureHandlers(Writer $log) + protected function configureHandler(Writer $log) { - if ($this->app->bound('config')) { - $handler = $this->app->make('config')->get('app.log'); - } else { - $handler = 'single'; - } - - $method = 'configure'.ucfirst($handler).'Handler'; - - $this->{$method}($log); + $this->{'configure'.ucfirst($this->handler()).'Handler'}($log); } /** @@ -110,6 +110,20 @@ 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'); + } + + return 'single'; + } + /** * Get the log level for the application. * diff --git a/src/Illuminate/Log/Writer.php b/src/Illuminate/Log/Writer.php index 884b70bf9956..239391af1f52 100755 --- a/src/Illuminate/Log/Writer.php +++ b/src/Illuminate/Log/Writer.php @@ -11,6 +11,7 @@ use Monolog\Handler\ErrorLogHandler; use Monolog\Logger as MonologLogger; use Monolog\Handler\RotatingFileHandler; +use Illuminate\Log\Events\MessageLogged; use Illuminate\Contracts\Support\Jsonable; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Support\Arrayable; @@ -275,7 +276,7 @@ public function listen(Closure $callback) throw new RuntimeException('Events dispatcher has not been set.'); } - $this->dispatcher->listen('illuminate.log', $callback); + $this->dispatcher->listen(MessageLogged::class, $callback); } /** @@ -292,7 +293,7 @@ protected function fireLogEvent($level, $message, array $context = []) // log listeners. These are useful for building profilers or other tools // that aggregate all of the log messages for a given "request" cycle. if (isset($this->dispatcher)) { - $this->dispatcher->fire('illuminate.log', compact('level', 'message', 'context')); + $this->dispatcher->fire(new MessageLogged($level, $message, $context)); } }