From cd4a10ed5726d296914bbf4234e2960385ebb686 Mon Sep 17 00:00:00 2001 From: "sergei.baikin" Date: Thu, 28 Jul 2022 09:22:38 +0200 Subject: [PATCH] Allow to set minimal log level --- README.md | 2 ++ composer.json | 2 +- src/Laravel/LaravelLoggerCreating.php | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b174a64..23e5068 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ add in `config/logging.php` in `channels` section: 'app_name' => 'ServiceName', 'channel' => 'app'(security/reauest/order), 'processors' => [new Monolog\Processor\ProcessorInterface()], //OPTIONAL + 'level' => Monolog\Logger::INFO, //OPTIONAL ] 'security' => [ 'driver' => 'custom', @@ -70,6 +71,7 @@ add in `config/logging.php` in `channels` section: 'app_name' => 'ServiceName', 'channel' => 'security', 'processors' => [new Monolog\Processor\ProcessorInterface()], //OPTIONAL + 'level' => Monolog\Logger::INFO, //OPTIONAL ], ``` diff --git a/composer.json b/composer.json index 14761db..6e68a38 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Integrate a common way for log handling.", "type": "library", "require": { - "php": "^7|^8", + "php": "^7.3|^8", "monolog/monolog": "^2.7|^3.1", "newrelic/monolog-enricher": "^2.0" }, diff --git a/src/Laravel/LaravelLoggerCreating.php b/src/Laravel/LaravelLoggerCreating.php index 676f782..4cdb50b 100644 --- a/src/Laravel/LaravelLoggerCreating.php +++ b/src/Laravel/LaravelLoggerCreating.php @@ -25,6 +25,8 @@ public function __invoke(array $config) $channel = $config['channel']; /** @var \Monolog\Processor\ProcessorInterface[] $processors */ $processors = $config['processors'] ?? []; + /** @var int $level */ + $level = $config['level'] ?? Logger::DEBUG; $log = new Logger($channel); $log->pushProcessor(new Processor()); @@ -33,7 +35,7 @@ public function __invoke(array $config) $log->pushProcessor($processor); } - $streamHandler = new StreamHandler('php://stderr'); + $streamHandler = new StreamHandler('php://stderr', $level); $handler = $streamHandler; $env = App::environment();