* @link http://www.yiiframework.com/ * @copyright Copyright © 2008-2009 Yii Software LLC * @license http://www.yiiframework.com/license/ */ /** * CLogRouter manages log routes that record log messages in different media. * * For example, a file log route {@link CFileLogRoute} records log messages * in log files. An email log route {@link CEmailLogRoute} sends log messages * to specific email addresses. See {@link 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',
 *                     'email'=>'admin@example.com',
 *                 ),
 *             ),
 *         ),
 *     ),
 * )
 * 
* * You can specify multiple routes with different filtering conditions and different * targets, even if the routes are of the same type. * * @author Qiang Xue * @version $Id: CLogRouter.php 1184 2009-06-28 00:30:10Z qiang.xue $ * @package system.logging * @since 1.0 */ class CLogRouter extends CApplicationComponent { private $_routes=array(); /** * Initializes this application component. * This method is required by the IApplicationComponent interface. */ public function init() { parent::init(); foreach($this->_routes as $name=>$route) { $route=Yii::createComponent($route); $route->init(); $this->_routes[$name]=$route; } Yii::app()->attachEventHandler('onEndRequest',array($this,'collectLogs')); } /** * @return array the currently initialized routes */ public function getRoutes() { return new CMap($this->_routes); } /** * @param array list of route configurations. Each array element represents * the configuration for a single route and has the following array structure: * */ public function setRoutes($config) { foreach($config as $name=>$route) $this->_routes[$name]=$route; } /** * Collects log messages from a logger. * This method is an event handler to application's onEndRequest event. * @param mixed event parameter */ public function collectLogs($param) { $logger=Yii::getLogger(); foreach($this->_routes as $route) { if($route->enabled) $route->collectLogs($logger); } } }