diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 6e030bf..27ca038 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -5,12 +5,14 @@ namespace SmartFrame\Logger; use Monolog\Handler\ElasticsearchHandler; +use Monolog\Handler\RotatingFileHandler; use Monolog\Handler\SocketHandler; use Monolog\Handler\StreamHandler; use Monolog\Logger; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use SmartFrame\Logger\HandlerFactory\ElasticsearchHandlerFactory; +use SmartFrame\Logger\HandlerFactory\RotatingFileHandlerFactory; use SmartFrame\Logger\HandlerFactory\SocketHandlerFactory; use SmartFrame\Logger\HandlerFactory\StreamHandlerFactory; use SmartFrame\Logger\Initializer\LoggerAwareInitializer; @@ -36,7 +38,8 @@ public function getDependencies(): array 'factories' => [ ElasticsearchHandler::class => ElasticsearchHandlerFactory::class, StreamHandler::class => StreamHandlerFactory::class, - SocketHandler::class => SocketHandlerFactory::class + SocketHandler::class => SocketHandlerFactory::class, + RotatingFileHandler::class => RotatingFileHandlerFactory::class, ], 'invokables' => [ NullLogger::class, diff --git a/src/HandlerFactory/RotatingFileHandlerFactory.php b/src/HandlerFactory/RotatingFileHandlerFactory.php new file mode 100644 index 0000000..ad7471e --- /dev/null +++ b/src/HandlerFactory/RotatingFileHandlerFactory.php @@ -0,0 +1,32 @@ +applyFormatters($handler, $options['formatter']); + } + + if (isset($options['properties'])) { + $this->applyProperties($handler, $options['properties']); + } + + return $this->applySpecialHandlers($handler, $options); + } +} diff --git a/test/HandlerFactory/RotatingFileHandlerFactoryTest.php b/test/HandlerFactory/RotatingFileHandlerFactoryTest.php new file mode 100644 index 0000000..cbde166 --- /dev/null +++ b/test/HandlerFactory/RotatingFileHandlerFactoryTest.php @@ -0,0 +1,23 @@ +createMock(ContainerInterface::class); + + $instance = (new RotatingFileHandlerFactory())->__invoke($containerMock, RotatingFileHandler::class, ['stream' => 'data/logs/test.log', 'maxFiles' => 2]); + + self::assertInstanceOf(RotatingFileHandler::class, $instance); + } +}