ZF-5741: Create the log file only if there is something to log

Issue Type: Improvement Created: 2009-02-11T00:48:16.000+0000 Last Updated: 2011-01-20T11:16:24.000+0000 Status: Open Fix version(s): Reporter: Mathieu Decaffmeyer (mathi) Assignee: Eddo Rotman (karnaf) Tags: - Zend_Log

Related issues: - ZF-7522

Attachments: - zf5741.r21176.patch


When you initialize the logger in the bootstrap file, for every request a log file will automatically be created if it doesn't exist, even when you do not plan to log.

I suggest to create the logfile only the first time something has to be logged.

Example: $logger = new Zend_Log(); $writer = new Zend_Log_Writer_Stream($path . "logfile-" . date("Ymd-H") . ".log"); $logger->addWriter($writer); I create a logfile per hour. If there is nothing to log for a specific day, this will create 24 empty logfiles, because the logfile is created in the constructor of Zend_Log_Writer_Stream.


Posted by julien PAULI (doctorrock83) on 2009-02-20T01:47:53.000+0000

mmm I see. You can use a different stream opening mode in the second parameter of Zend_Log_Writer_Stream constructor. By default, 'a' is used, which effectively tries to create the file if it doesn't exist.

Anyway, your problem seems deeper as you want to create it if it doesn't exist only while the first writting operation.

If Zend_Log whould be given such a behavior then it has to be patched deeper.

Posted by Wil Sinclair (wil) on 2009-03-16T10:50:11.000+0000

There's also a usability issue here. An empty log file indicates that Zend_Log is working and logging where you expect it to log, but there were no events to log. If we implement this, it would have to be an option that is off by default IMO.


Posted by Dolf Schimmel (Freeaqingme) (freak) on 2009-03-16T10:53:25.000+0000

Agreed with Wil. I cannot see how this is btw a major improvement, setting straight.

Posted by Goran Juric (gog) on 2009-11-12T15:03:00.000+0000

I do not see the need for this. If you do not plan to log, there is no need to instantiate the log object.

Lazy loading the log object will solve the problem of generating empty log files.

Posted by Michael Rehbein (tech13) on 2010-02-23T12:33:46.000+0000

Patch contains: - Adjustments to Zend_Log_Writer_Stream to allow lazy opening - Unit tests for Lazy opening - Documentation for factory and class about lazy opening

Posted by Mathieu Decaffmeyer (mathi) on 2010-08-17T05:38:01.000+0000

Goran Juric @ If you do not plan to log, there is no need to instantiate the log object.

You may want to log for errors; if no errors occur, in the example above a log file will be created every hour wether there is something to log or not.

@Michael Rehbein

Will the patch be included in the framework ?

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.