标签:
Messages logged using Yii::log or Yii::trace are kept in memory. We usually need to display them in browser windows, or save them in some persistent storage such as files, emails. This is called message routing, i.e., sending messages to different destinations.
In Yii, message routing is managed by a CLogRouter application component. It manages a set of the so-calledlog routes. Each log route represents a single log destination. Messages sent along a log route can be filtered according to their levels and categories.
To use message routing, we need to install and preload a CLogRouter application component. We also need to configure its routes property with the log routes that we want. The following shows an example of the needed application configuration:
array(
......
‘preload‘=>array(‘log‘),
‘components‘=>array(
......
‘log‘=>array(
‘class‘=>‘CLogRouter‘,
‘routes‘=>array(
array(
‘class‘=>‘CFileLogRoute‘,
‘levels‘=>‘trace, info‘,
‘categories‘=>‘system.*‘,
),
array(
‘class‘=>‘CEmailLogRoute‘,
‘levels‘=>‘error, warning‘,
‘emails‘=>‘admin@example.com‘,
),
),
),
),
)
In the above example, we have two log routes. The first route is CFileLogRoute which saves messages in a file under the application runtime directory. Only messages whose level is trace
or info
and whose category starts with system.
are saved. The second route is CEmailLogRoute which sends messages to the specified email addresses. Only messages whose level is error
or warning
are sent.
标签:
原文地址:http://www.cnblogs.com/51cas/p/4519931.html