application.ini 中具有多个写入器的 Zend_Log

发布于 2024-12-03 18:54:57 字数 842 浏览 3 评论 0原文

我的配置中有一个记录器,如下所示:

resources.log.stream.writerName = "Stream"
resources.log.stream.writerParams.stream = APPLICATION_PATH "/../logs/err.log"
resources.log.stream.writerParams.mode = "a"
resources.log.stream.filterName = "Priority"
resources.log.stream.filterParams.priority = 3

但我只想将它用于错误日志。对于另一个日志想使用另一个日志文件。因此,我将这些行添加到了 app.ini

resources.log.stream.writerName = "Stream"
resources.log.stream.writerParams.stream[] = APPLICATION_PATH "/../logs/debug.log"
resources.log.stream.writerParams.stream[] = APPLICATION_PATH "/../logs/info.log"
resources.log.stream.writerParams.mode = "a"
resources.log.stream.filterName = "Priority"
resources.log.stream.filterParams.priority[] = 7
resources.log.stream.filterParams.priority[] = 5

但这不起作用,我想对不同的优先级使用不同的文件。但记录器会覆盖第一个记录器。如何 ?

i have a logger in my config like this:

resources.log.stream.writerName = "Stream"
resources.log.stream.writerParams.stream = APPLICATION_PATH "/../logs/err.log"
resources.log.stream.writerParams.mode = "a"
resources.log.stream.filterName = "Priority"
resources.log.stream.filterParams.priority = 3

But i want to use it for only error logs. For another logs wanna use another log file. For that reason i added these lines to app.ini

resources.log.stream.writerName = "Stream"
resources.log.stream.writerParams.stream[] = APPLICATION_PATH "/../logs/debug.log"
resources.log.stream.writerParams.stream[] = APPLICATION_PATH "/../logs/info.log"
resources.log.stream.writerParams.mode = "a"
resources.log.stream.filterName = "Priority"
resources.log.stream.filterParams.priority[] = 7
resources.log.stream.filterParams.priority[] = 5

But this is not working i wanna use differetn files for different priorities. But logger overrides the first logger. How ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彼岸花ソ最美的依靠 2024-12-10 18:54:57

application.ini 示例:

resources.log.err.writerName = "Stream"
resources.log.err.writerParams.stream =  APPLICATION_PATH "/../data/logs/ERR.log"
;resources.log.stream.formatterParams.format = "%priority%:%message% %timestamp% %priorityName%  %info% PHP_EOL"
resources.log.err.filterName = "Priority"
resources.log.err.filterParams.priority = 3
resources.log.err.filterParams.operator = "=="

resources.log.warn.writerName = "Stream"
resources.log.warn.writerParams.stream = APPLICATION_PATH "/../data/logs/WARN.log"
;resources.log.warn.formatterParams.format = "%priority%:%message%:%ip%:%userid% %timestamp% %priorityName%  %info% PHP_EOL"
resources.log.warn.filterName = "Priority"
resources.log.warn.filterParams.priority = 4
resources.log.warn.filterParams.operator = "=="

在 bootstrap 中:

protected function _initLog() {
    $options = $this->getOption('resources');
    $partitionConfig = $this->getOption('log');
    $logOptions = $options['log'];
    $logger = Zend_Log::factory($logOptions);
    $logger->addPriority('USERACTION', 8);
    $logger->addPriority('DBLOG', 9);
    Zend_Registry::set('logger', $logger);
}

然后在代码中:

$this->logger = Zend_Registry::get('logger');
$this->logger->setEventItem('ip', $_SERVER['REMOTE_ADDR']);
$this->logger->setEventItem('userid', $this->userId);

使用这种方式:

$this->logger->log('Test error', Zend_Log::WARN);

或这种方式:

$this->logger->warn('Test error');

或这种方式:

$this->logger->log('Test error', 4);

Example of application.ini:

resources.log.err.writerName = "Stream"
resources.log.err.writerParams.stream =  APPLICATION_PATH "/../data/logs/ERR.log"
;resources.log.stream.formatterParams.format = "%priority%:%message% %timestamp% %priorityName%  %info% PHP_EOL"
resources.log.err.filterName = "Priority"
resources.log.err.filterParams.priority = 3
resources.log.err.filterParams.operator = "=="

resources.log.warn.writerName = "Stream"
resources.log.warn.writerParams.stream = APPLICATION_PATH "/../data/logs/WARN.log"
;resources.log.warn.formatterParams.format = "%priority%:%message%:%ip%:%userid% %timestamp% %priorityName%  %info% PHP_EOL"
resources.log.warn.filterName = "Priority"
resources.log.warn.filterParams.priority = 4
resources.log.warn.filterParams.operator = "=="

In bootstrap:

protected function _initLog() {
    $options = $this->getOption('resources');
    $partitionConfig = $this->getOption('log');
    $logOptions = $options['log'];
    $logger = Zend_Log::factory($logOptions);
    $logger->addPriority('USERACTION', 8);
    $logger->addPriority('DBLOG', 9);
    Zend_Registry::set('logger', $logger);
}

Then in codes:

$this->logger = Zend_Registry::get('logger');
$this->logger->setEventItem('ip', $_SERVER['REMOTE_ADDR']);
$this->logger->setEventItem('userid', $this->userId);

Use this way:

$this->logger->log('Test error', Zend_Log::WARN);

Or this way:

$this->logger->warn('Test error');

Or this way:

$this->logger->log('Test error', 4);
不疑不惑不回忆 2024-12-10 18:54:57

您可以使用过滤器来完成此操作。只需让较高优先级的事件通过过滤器,直到您想要记录它们即可。

http://framework.zend.com/manual/en/zend.log .filters.html

您的设置中的问题是您试图使用不应该使用的同一编写器。使用过滤器选择写入器并将某些日志文件与某些写入器关联,如示例的第二部分所示。

我认为类似的事情应该可以解决问题:

resources.log.stream.writerName = "myDebugWriter"
resources.log.stream.writerParams.stream = APPLICATION_PATH "/../logs/debug.log"
resources.log.stream.filterName = "Priority"
resources.log.stream.filterParams.priority = Zend_Log::WARN
resources.log.stream.writerName = "myInfoWriter"
resources.log.stream.writerParams.stream = APPLICATION_PATH "/../logs/info.log"
resources.log.stream.filterName = "Priority"
resources.log.stream.filterParams.priority = Zend_Log::INFO

You can use filters to accomplish this. Just let higher priority events pass through the filters until you want to log them.

http://framework.zend.com/manual/en/zend.log.filters.html

What's wrong in your setup is that you are trying to use the same writer which you should not. Use the filters to choose the writers and associate certain log files with certain writers, as shown in the second part of the example.

I think something like that should do the trick:

resources.log.stream.writerName = "myDebugWriter"
resources.log.stream.writerParams.stream = APPLICATION_PATH "/../logs/debug.log"
resources.log.stream.filterName = "Priority"
resources.log.stream.filterParams.priority = Zend_Log::WARN
resources.log.stream.writerName = "myInfoWriter"
resources.log.stream.writerParams.stream = APPLICATION_PATH "/../logs/info.log"
resources.log.stream.filterName = "Priority"
resources.log.stream.filterParams.priority = Zend_Log::INFO
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文