开发者

Relative path for Zend_Log in Zend Framework

开发者 https://www.devze.com 2023-01-24 07:03 出处:网络
I am trying to work out the best way to configure my Zend_Log_Writer_Stream instance to write t开发者_开发问答o a filename relative to my APPLICATION_PATH.

I am trying to work out the best way to configure my Zend_Log_Writer_Stream instance to write t开发者_开发问答o 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.


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 /).


Zend_Config_Ini uses parse_ini_file internally to read the application.ini. This means, it should parse constants. Please try with your ideal approach. Make sure the constant is defined prior to loading the application.ini

EDIT: Also see Stefan Gehrig's note about the correct format to use

0

精彩评论

暂无评论...
验证码 换一张
取 消