发布于 2015-10-07 09:54:51 | 159 次阅读 | 评论: 0 | 来源: 网络整理

24.4. 过滤器

一个Filter对象阻塞一个消息被写入到日志.

24.4.1. 对所有Writer过滤

要在所有writer之前过滤消息,你可以使用addFilter()方法添加任意数量的Filter到Log对象:

$logger = new Zend_Log();

$writer = new Zend_Log_Writer_Stream('php://output');
$logger->addWriter($writer);

$filter = new Zend_Log_Filter_Priority(Zend_Log::CRIT);
$logger->addFilter($filter);

// blocked
$logger->info('Informational message');

// logged
$logger->emerg('Emergency message');

        

当你添加一个或多个Filter到Log对象后,消息在任何Writer接收之前必须通过所有的Filter.

24.4.2. 过滤一个Writer实例

要在一个特定的Writer上进行消息过滤,使用该Writer对象的addFilter()方法:

$logger = new Zend_Log();

$writer1 = new Zend_Log_Writer_Stream('/path/to/first/logfile');
$logger->addWriter($writer1);

$writer2 = new Zend_Log_Writer_Stream('/path/to/second/logfile');
$logger->addWriter($writer2);

// add a filter only to writer2
$filter = new Zend_Log_Filter_Priority(Zend_Log::CRIT);
$writer2->addFilter($filter);

// logged to writer1, blocked from writer2
$logger->info('Informational message');

// logged by both writers
$logger->emerg('Emergency message');

        

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务