coogle / logger
为 Zend Framework 2 设计的事件驱动日志模块
dev-master
2014-01-31 02:02 UTC
Requires
- zendframework/zendframework: >2.2.0
This package is not auto-updated.
Last update: 2024-09-28 14:37:56 UTC
README
介绍
这是一个相对简单的 ZF2 日志模块。它通过连接到 'log' 事件,允许它捕获触发该事件的任何模块的日志事件。
配置
日志类在 logger
键下提供了以下配置值,如下所示
array(
'logger' => array(
'db_adapter' => null,
'logger_table' => 'application_log',
'priority_filter' => Logger::DEBUG,
'log_file' => '/tmp/application.log'
)
);
db_adapter
是用于数据库日志的数据库适配器(例如Zend\Db\Adapter\Adapter
或此类适配器)logger_table
是写入日志条目的表(模式在 sql/create.sql 中定义)priority_filter
当写入日志条目时要过滤的优先级log_file
要记录事件的本地文件系统上的文件
使用方法
要使用日志记录器,你可以触发一个 'log' 事件,例如以下示例来自实现 ServiceLocatorAwareInterface
的类
$eventManager = $this->getServiceLocator()->get('Application')->getEventManager();
$eventManager->trigger('log', $this, array('message' => "Testing Logging", 'priority' => Logger::ERR));
或者,Logger 模块附带一个 Logger\LoggerTrait
特性,可以被使用(提供了一个 logEvent(<message>, <priority>)
方法,可以在任何提供 ServiceLocatorAwareInterface
的类中使用)。