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?
unlink
nothing is escalated and it silently does nothing. I suppose you checked file permissions (a bit unlikely, the user that created the file should also be able to delete it again ...). – Serialize600
. I run script via cli. I've added test code to my script:is_writeable
returnstrue
,unlink
is ok when call them argument equal to path to one of the logs. @Tzook Bar Noy,app-2018-08-20.log
,app-2018-08-19.log
and so on. Nothing special, I think. – Alvordapp.log
is writable but the old log files maybe not. The second reason is if you run the script with the cronjob, it may run with another user permission. – Whallsudo -u cronuser /usr/bin/php /path/to/cronjob
– Demeanorls -al
) – Whallecho exec('id -gn') . ' ' . exec('id -un') . "\n"; exit;
code to the start of the script. It should output the group and name of user who runs script I think. Direct cli run and run via cron produces the same results. Maybe there were some changes in server configuration but for now in my tests logs are rotated ok without any changes in code. I'am really surprised. – Alvord