Search code examples
zend-frameworkbootstrappingzend-log

Relative path for Zend_Log in Zend Framework


I am trying to work out the best way to configure my Zend_Log_Writer_Stream instance to write to a filename relative to my APPLICATION_PATH.

For example, with the following config:

resources.log.stream.writerName = "Stream"
resources.log.stream.writerParams.stream = "logs/production.log"

The normal way to init your loggger would be to either use the application bootstrap resource or do the following:

$logger = Zend_Log::factory($config->resources->log);

The problem with this is that the Zend_Log_Writer_Stream::factory method will try to access the file relative to the current script execution, not the APPLICATION_PATH.

As it's almost always the index.php inside /public that kicks this off usually it's not a drama, however when I execute individual scripts inside my unit testing directories it will use that directory to base the path on.

Ideally I want to be able to set:

resources.log.stream.writerParams.stream = APPLICATION_PATH . "../logs/production.log"

So that it always uses a predictable location. I would rather not have to hack the factory method of a Zend_Log inherited class to make this work.

I would love to hear how others have solved this problem.


Solution

  • resources.log.stream.writerParams.stream = APPLICATION_PATH "../logs/production.log"
    

    should work. parse_ini_file() (which is used by Zend_Config_Ini) allows for the use of constants - but concatenation doesn't work like in PHP (with the . operator); just append the static string to the constant (you might need an additional / if APPLICATION_PATH doesn't end with a /).