From d4996170ec0ea2d5189db213c51ebcf4f526ab6d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 14 Mar 2018 07:38:13 -0500 Subject: [PATCH] formatting --- src/Illuminate/Log/LogManager.php | 29 +++++++++++++---------------- tests/Log/LogManagerTest.php | 8 ++++---- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 1194d78a5149..75eb9903f87c 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -320,30 +320,27 @@ protected function createErrorlogDriver(array $config) } /** - * Create an instance of any handler available in Monolog from configuration. + * Create an instance of any handler available in Monolog. * - * @param array $config - * @return \Monolog\Logger + * @param array $config + * @return \Psr\Log\LoggerInterface + * + * @throws \InvalidArgumentException * @throws \Illuminate\Contracts\Container\BindingResolutionException */ protected function createMonologDriver(array $config) { - if (isset($config['handler_type'])) { - $handlerClass = 'Monolog\Handler\\'.ucfirst($config['handler_type']).'Handler'; - } elseif (isset($config['handler_class'])) { - $handlerClass = $config['handler_class']; - } else { - throw new InvalidArgumentException('"handler_type" or "handler_class" is required for the monolog driver'); + if (! is_a($config['handler'], HandlerInterface::class, true)) { + throw new InvalidArgumentException( + $config['handler'].' must be an instance of '.HandlerInterface::class + ); } - if (! is_a($handlerClass, HandlerInterface::class, true)) { - throw new InvalidArgumentException($handlerClass.' must be an instance of '.HandlerInterface::class); - } + $handlers = [$this->prepareHandler( + $this->app->make($config['handler'], $config['with'] ?? []) + )]; - return new Monolog( - $this->parseChannel($config), - [$this->prepareHandler($this->app->make($handlerClass, $config['handler_params'] ?? []))] - ); + return new Monolog($this->parseChannel($config), $handlers); } /** diff --git a/tests/Log/LogManagerTest.php b/tests/Log/LogManagerTest.php index ff3054e484f3..35206c457b96 100755 --- a/tests/Log/LogManagerTest.php +++ b/tests/Log/LogManagerTest.php @@ -28,8 +28,8 @@ public function testLogManagerCreatesConfiguredMonologHandler() $config->set('logging.channels.nonbubblingstream', [ 'driver' => 'monolog', 'name' => 'foobar', - 'handler_type' => 'stream', - 'handler_params' => [ + 'handler' => StreamHandler::class, + 'with' => [ 'stream' => 'php://stderr', 'level' => Monolog::NOTICE, 'bubble' => false, @@ -56,8 +56,8 @@ public function testLogManagerCreatesConfiguredMonologHandler() $config->set('logging.channels.logentries', [ 'driver' => 'monolog', 'name' => 'le', - 'handler_type' => 'LogEntries', - 'handler_params' => [ + 'handler' => LogEntriesHandler::class, + 'with' => [ 'token' => '123456789', ], ]);