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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.