PHP 7.1, ubuntu 12.04 LTS, monolog version is 1.23.0.
Logger initialisation:
<?php
$logger = new Logger('app');
$logger->pushHandler(
new RotatingFileHandler(
Main\Application::getDocumentRoot() . '/runtime/logs/app.log',
5,
Logger::DEBUG
)
);
Currently there is 24 log files in the path, not 5 as expected.
How to force monolog to rotate files as expected? Do I need do some extra steps to rotate files, what reason may cause not deleting old logs?
Try the below code...
$logger = new Logger('app');
$handler = new RotatingFileHandler(Main\Application::getDocumentRoot() . '/runtime/logs/app.log', 5, Logger::DEBUG, true, 0664);
//$handler->setFilenameFormat('{date}-{filename}', 'Y/m/d');
$logger->pushHandler($handler);
$array = ["x" => "y"];
$logger->addInfo('new message', $array);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With