Reputation: 1893
I use the Zend Log for logging information to my logfile. I am looking forward for a way to automatically write in monthly logfiles like logfile201601.log, logile201602.log etc.
Is there a way to to achieve that ? Any hints or a tutorial ? Didn't found anything like that on my current research.
My current configuration:
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
'Zend\Log' => function ($sm) {
$logger = new Zend\Log\Logger(array(
'writers' => array(
'stream' => array(
'name' => 'stream',
'options' => array(
'stream' => './data/log/logfile2016.log',
'formatter' => array(
'name' => 'simple',
'options' => array(
'dateTimeFormat' => 'Y-m-d H:i:s'
)
)
)
)
)
));
return $logger;
},
);
Upvotes: 1
Views: 413
Reputation: 1748
Because Zend will automatically create the log file, you can just dynamically create your log file with the date()
function:
// ...
'stream' => './data/log/logfile'.date("Ym").'.log',
// ...
Note that the log
directory must be writable.
Upvotes: 2