system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.cubrid system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.gii system.i18n system.i18n.gettext system.logging system.test system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.form system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers zii.behaviors zii.widgets zii.widgets.grid zii.widgets.jui

CLogRoute

system.logging
继承 abstract class CLogRoute » CComponent
子类 CDbLogRoute, CEmailLogRoute, CFileLogRoute, CSysLogRoute, CWebLogRoute
可用自 1.0
源码 framework/logging/CLogRoute.php
CLogRoute is the base class for all log route classes.

A log route object retrieves log messages from a logger and sends it somewhere, such as files, emails. The messages being retrieved may be filtered first before being sent to the destination. The filters include log level filter and log category filter.

To specify level filter, set levels property, which takes a string of comma-separated desired level names (e.g. 'Error, Debug'). To specify category filter, set categories property, which takes a string of comma-separated desired category names (e.g. 'System.Web, System.IO').

Level filter and category filter are combinational, i.e., only messages satisfying both filter conditions will they be returned.

公共属性

隐藏继承的属性

属性类型描述被定义在
categories mixed array of categories, or string list separated by comma or space. CLogRoute
enabled boolean whether to enable this log route. CLogRoute
except mixed array of categories, or string list separated by comma or space, to EXCLUDE from logs. CLogRoute
filter mixed the additional filter (eg CLogFilter) that can be applied to the log messages. CLogRoute
levels string list of levels separated by comma or space. CLogRoute
logs array the logs that are collected so far by this log route. CLogRoute

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. CComponent
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
collectLogs() Retrieves filtered log messages from logger for further processing. CLogRoute
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
evaluateExpression() Evaluates a PHP expression or callback under the context of this component. CComponent
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
init() Initializes the route. CLogRoute
raiseEvent() Raises an event. CComponent

受保护的方法

隐藏继承的方法

方法描述被定义在
formatLogMessage() Formats a log message given different fields. CLogRoute
processLogs() Processes log messages and sends them to specific destination. CLogRoute

属性详情

categories 属性
public mixed $categories;

array of categories, or string list separated by comma or space. Defaults to empty array, meaning all categories.

enabled 属性
public boolean $enabled;

whether to enable this log route. Defaults to true.

except 属性
public mixed $except;

array of categories, or string list separated by comma or space, to EXCLUDE from logs. Defaults to empty array, meaning no categories are excluded. This will exclude any categories after $categories has been ran.

filter 属性
public mixed $filter;

the additional filter (eg CLogFilter) that can be applied to the log messages. The value of this property will be passed to Yii::createComponent to create a log filter object. As a result, this can be either a string representing the filter class name or an array representing the filter configuration. In general, the log filter class should implement ILogFilter interface. If you want to apply multiple filters you can use CChainedLogFilter to do so. Defaults to null, meaning no filter will be used.

levels 属性
public string $levels;

list of levels separated by comma or space. Defaults to empty, meaning all levels.

logs 属性 (自版本 v1.1.0 可用)
public array $logs;

the logs that are collected so far by this log route.

方法详情

collectLogs() 方法
public void collectLogs(CLogger $logger, boolean $processLogs=false)
$logger CLogger logger instance
$processLogs boolean whether to process the logs after they are collected from the logger
源码: framework/logging/CLogRoute.php#95 (显示)
public function collectLogs($logger$processLogs=false)
{
    
$logs=$logger->getLogs($this->levels,$this->categories,$this->except);
    
$this->logs=empty($this->logs) ? $logs array_merge($this->logs,$logs);
    if(
$processLogs && !empty($this->logs))
    {
        if(
$this->filter!==null)
            
Yii::createComponent($this->filter)->filter($this->logs);
        if(
$this->logs!==array())
            
$this->processLogs($this->logs);
        
$this->logs=array();
    }
}

Retrieves filtered log messages from logger for further processing.

formatLogMessage() 方法
protected string formatLogMessage(string $message, integer $level, string $category, integer $time)
$message string message content
$level integer message level
$category string message category
$time integer timestamp
{return} string formatted message
源码: framework/logging/CLogRoute.php#85 (显示)
protected function formatLogMessage($message,$level,$category,$time)
{
    return @
date('Y/m/d H:i:s',$time)." [$level] [$category$message\n";
}

Formats a log message given different fields.

init() 方法
public void init()
源码: framework/logging/CLogRoute.php#73 (显示)
public function init()
{
}

Initializes the route. This method is invoked after the route is created by the route manager.

processLogs() 方法
abstract protected void processLogs(array $logs)
$logs array list of messages. Each array element represents one message with the following structure: array( [0] => message (string) [1] => level (string) [2] => category (string) [3] => timestamp (float, obtained by microtime(true));
源码: framework/logging/CLogRoute.php#120 (显示)
abstract protected function processLogs($logs);

Processes log messages and sends them to specific destination. Derived child classes must implement this method.