CLogRouter
CLogRouter manages log routes that record log messages in different media.
For example, a file log route
CFileLogRoute records log messages in log files. An email log route
CEmailLogRoute sends log messages to specific email addresses. See
CLogRoute for more details about different log routes.
Log routes may be configured in application configuration like following:
array(
'preload'=>array('log'), // preload log component when app starts
'components'=>array(
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'trace, info',
'categories'=>'system.*',
),
array(
'class'=>'CEmailLogRoute',
'levels'=>'error, warning',
'emails'=>array('[email protected]'),
),
),
),
),
)
You can specify multiple routes with different filtering conditions and different targets, even if the routes are of the same type.
Property Details
public array getRoutes()
public void setRoutes(array $config)
the currently initialized routes
Method Details
public void collectLogs(CEvent $event) |
$event | CEvent | event parameter |
Source Code: framework/logging/CLogRouter.php#100 (
show)
public function collectLogs($event)
{
$logger=Yii::getLogger();
$dumpLogs=isset($event->params['dumpLogs']) && $event->params['dumpLogs'];
foreach($this->_routes as $route)
{
/* @var $route CLogRoute */
if($route->enabled)
$route->collectLogs($logger,$dumpLogs);
}
}
Collects log messages from a logger. This method is an event handler to the CLogger::onFlush event.
public array getRoutes() |
{return} | array | the currently initialized routes |
Source Code: framework/logging/CLogRouter.php#60 (
show)
public function init()
{
parent::init();
foreach($this->_routes as $name=>$route)
{
$route=Yii::createComponent($route);
$route->init();
$this->_routes[$name]=$route;
}
Yii::getLogger()->attachEventHandler('onFlush',array($this,'collectLogs'));
Yii::app()->attachEventHandler('onEndRequest',array($this,'processLogs'));
}
Initializes this application component. This method is required by the IApplicationComponent interface.
public void processLogs() |
Collects and processes log messages from a logger. This method is an event handler to the CApplication::onEndRequest event.
public void setRoutes(array $config) |
$config | array | list of route configurations. Each array element represents the configuration for a single route and has the following array structure: - class: specifies the class name or alias for the route class.
- name-value pairs: configure the initial property values of the route.
|