0

I am using slim3 with monolog from composer my dependencies is looks like that:

// monolog

$container['logger'] = function ($c) {
    $settings = $c->get('settings')['logger'];
    $logger = new Monolog\Logger($settings['name']);
    $logger->pushProcessor(new Monolog\Processor\UidProcessor());
    $logger->pushHandler(new Monolog\Handler\RotatingFileHandler($settings['path'], $settings['level']));
    return $logger;
};

I did not manage to set limit(filesize) for those logs basically, my log file name looks like: server-[date].log

I want to create a new log when it exceeded the 5MB for example:

 server-[todaydate].log
 server-[todaydate]-1.log
 server-[todaydate]-2.log
Tuz
  • 1,810
  • 5
  • 29
  • 58
  • I don't see a number `5` in your code. Try, then come back with some code. – aaron Dec 04 '17 at 12:49
  • Don't know how to do that. asking for help – Tuz Dec 04 '17 at 14:02
  • you can find last log file, then get it size by filesize() function in php. then you can check if file size of last log file is greater than 5 mb create new one else write to last log file.@tuz – Javid Karimov Dec 04 '17 at 15:17
  • Do you insist on doing this from your PHP code? Or other methods are OK? Because you can achieve this using some other tools like `logrotate` utility. Monolog has a `RotatingFileHandler` but it rotates log files based on date and time, not size. They recommend using `logrotate` even for this type of rotation. Have a look at this https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/RotatingFileHandler.php – Nima Dec 04 '17 at 17:21
  • How Can i use logrotate in my slim.php . (windows env) – Tuz Dec 05 '17 at 06:13
  • There are some answers to similar question here https://serverfault.com/questions/358172/equivalent-of-logrotate-for-windows – Nima Dec 07 '17 at 15:01

0 Answers0