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


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.


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.

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.


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

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.

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

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 ?