Zend Framework 中 Zend_Log 的相对路径
我正在尝试找出配置 Zend_Log_Writer_Stream 实例以写入相对于我的 APPLICATION_PATH 的文件名的最佳方法。
例如,使用以下配置:
resources.log.stream.writerName = "Stream"
resources.log.stream.writerParams.stream = "logs/production.log"
初始化记录器的正常方法是使用应用程序引导资源或执行以下操作:
$logger = Zend_Log::factory($config->resources->log);
这样做的问题是 Zend_Log_Writer_Stream::factory 方法将尝试访问相对于当前脚本执行,而不是 APPLICATION_PATH。
因为它几乎总是 /public 内的 index.php 启动,通常这不是一场戏剧,但是当我在单元测试目录中执行单个脚本时,它将使用该目录作为路径的基础。
理想情况下,我希望能够设置:
resources.log.stream.writerParams.stream = APPLICATION_PATH . "../logs/production.log"
以便它始终使用可预测的位置。我宁愿不必破解 Zend_Log 继承类的工厂方法来完成这项工作。
我很想听听其他人如何解决这个问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该有效。
parse_ini_file()
(由Zend_Config_Ini
使用)允许使用常量 - 但连接不像 PHP 中那样工作(使用.
运算符);只需将静态字符串附加到常量(如果APPLICATION_PATH
不以/
结尾,您可能需要额外的/
)。should work.
parse_ini_file()
(which is used byZend_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/
ifAPPLICATION_PATH
doesn't end with a/
).Zend_Config_Ini
使用parse_ini_file
内部读取application.ini。这意味着,它应该解析常量。请尝试您理想的方法。确保在加载 application.ini 之前定义常量编辑:另请参阅 Stefan Gehrig 关于要使用的正确格式的注释
Zend_Config_Ini
usesparse_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.iniEDIT: Also see Stefan Gehrig's note about the correct format to use