CFileLogRoute

优质
小牛编辑
122浏览
2023-12-01
所有包 | 属性 | 方法
system.logging
继承class CFileLogRoute » CLogRoute » CComponent
源自1.0
版本$Id: CFileLogRoute.php 3426 2011-10-25 00:01:09Z alexander.makarow $
源码framework/logging/CFileLogRoute.php
CFileLogRoute用文件记录日志信息。

日志文件被存储在 logPath 下 并且文件名可以通过 logFile 指定。 如果日志文件的大小大于maxFileSize(用kilo-bytes), 将进行一次循环 ,这将通过给文件名加前缀‘.1’来重命名当前日志文件。 所有已经存在的日志文件被移动到向后的一个位置, 例如,‘.2’ 到‘.3’,‘.1’,‘到’,‘.2’。 属性 maxLogFiles 指定保持多少个文件.

公共属性

隐藏继承属性

属性类型描述定义在
categoriesstring被逗号或空格分隔的类别列表。默认为空,意味着所有类别。CLogRoute
enabledboolean是否启用这个日志路由。默认为true。CLogRoute
filtermixed附加过滤器 (例如 CLogFilter) 它被应用到日志信息。 这个属性的值被传递到 Yii::createComponent 创建一个日志过滤器对象。 结果,这可能是一个表示过滤器类名的字符串或一个表示过滤器配置的数组。

总之,日志过滤器类应该是 CLogFilter 或它的一个子类。 默认为null,意味着没有过滤器被使用。
CLogRoute
levelsstring用逗号或空格分隔的等级列表。默认是空,意味着所有等级。CLogRoute
logFilestring日志文件名。默认是‘application.CFileLogRoute
logPathstring存储日志文件目录。默认是应用程序 runtime 路径。CFileLogRoute
logsarray到目前为止这个日志路由搜集的日志。CLogRoute
maxFileSizeinteger最大日志文件尺寸(KB)。默认是1024 (1MB)。CFileLogRoute
maxLogFilesinteger轮流的文件数。默认是5。CFileLogRoute

公共方法

隐藏继承方法

方法描述定义在
__call()如果类中没有调的方法名,则调用这个方法。CComponent
__get()返回一个属性值、一个事件处理程序列表或一个行为名称。CComponent
__isset()检查一个属性是否为null。CComponent
__set()设置一个组件的属性值。CComponent
__unset()设置一个组件的属性为null。CComponent
asa()返回这个名字的行为对象。CComponent
attachBehavior()附加一个行为到组件。CComponent
attachBehaviors()附加一个行为列表到组件。CComponent
attachEventHandler()为事件附加一个事件处理程序。CComponent
canGetProperty()确定属性是否可读。CComponent
canSetProperty()确定属性是否可写。CComponent
collectLogs()从日志记录器取回已过滤的日志信息以便进一步处理。CLogRoute
detachBehavior()从组件中分离一个行为。CComponent
detachBehaviors()从组件中分离所有行为。CComponent
detachEventHandler()分离一个存在的事件处理程序。CComponent
disableBehavior()禁用一个附加行为。CComponent
disableBehaviors()禁用组件附加的所有行为。CComponent
enableBehavior()启用一个附加行为。CComponent
enableBehaviors()启用组件附加的所有行为。CComponent
evaluateExpression()计算一个PHP表达式,或根据组件上下文执行回调。CComponent
getEventHandlers()返回一个事件的附加处理程序列表。CComponent
getLogFile()返回日志文件名。默认是‘application.log’。CFileLogRoute
getLogPath()返回存储日志文件目录。默认是应用程序 runtime 路径。CFileLogRoute
getMaxFileSize()返回最大日志文件尺寸(KB)。默认是1024 (1MB)。CFileLogRoute
getMaxLogFiles()返回轮流的文件数。默认是5。CFileLogRoute
hasEvent()确定一个事件是否定义。CComponent
hasEventHandler()检查事件是否有附加的处理程序。CComponent
hasProperty()确定属性是否被定义。CComponent
init()初始化此路由。CFileLogRoute
raiseEvent()发起一个事件。CComponent
setLogFile()设置日志文件名CFileLogRoute
setLogPath()设置存储日志文件目录.CFileLogRoute
setMaxFileSize()设置日志文件的最大尺寸(KB)。CFileLogRoute
setMaxLogFiles()设置用于轮流的文件数。CFileLogRoute

受保护方法

隐藏继承方法

方法描述定义在
formatLogMessage()格式化一条日志信息已给定不同字段。CLogRoute
processLogs()保存日志信息在文件中。CFileLogRoute
rotateFiles()轮流日志文件。CFileLogRoute

属性详细

logFile 属性 public string getLogFile()
public void setLogFile(string $value)

日志文件名。默认是‘application.log’。

logPath 属性 public string getLogPath()
public void setLogPath(string $value)

存储日志文件目录。默认是应用程序 runtime 路径。

maxFileSize 属性 public integer getMaxFileSize()
public void setMaxFileSize(integer $value)

最大日志文件尺寸(KB)。默认是1024 (1MB)。

maxLogFiles 属性 public integer getMaxLogFiles()
public void setMaxLogFiles(integer $value)

轮流的文件数。默认是5。

方法详细

getLogFile() 方法
public string getLogFile()
{return}string日志文件名。默认是‘application.log’。
源码: framework/logging/CFileLogRoute.php#86 (显示) publicfunctiongetLogFile()
{
return$this->_logFile;
}
getLogPath() 方法
public string getLogPath()
{return}string存储日志文件目录。默认是应用程序 runtime 路径。
源码: framework/logging/CFileLogRoute.php#66 (显示) publicfunctiongetLogPath()
{
return$this->_logPath;
}
getMaxFileSize() 方法
public integer getMaxFileSize()
{return}integer最大日志文件尺寸(KB)。默认是1024 (1MB)。
源码: framework/logging/CFileLogRoute.php#102 (显示) publicfunctiongetMaxFileSize()
{
return$this->_maxFileSize;
}
getMaxLogFiles() 方法
public integer getMaxLogFiles()
{return}integer轮流的文件数。默认是5。
源码: framework/logging/CFileLogRoute.php#119 (显示) publicfunctiongetMaxLogFiles()
{
return$this->_maxLogFiles;
}
init() 方法
public void init()
源码: framework/logging/CFileLogRoute.php#56 (显示) publicfunctioninit()
{
parent::init();
if($this->getLogPath()===null)
$this->setLogPath(Yii::app()->getRuntimePath());
}

初始化此路由。 这个方法被发起在路由管理器创建此路由之后。

processLogs() 方法
protected void processLogs(array $logs)
$logsarray日志信息列表
源码: framework/logging/CFileLogRoute.php#137 (显示) protectedfunctionprocessLogs($logs)
{
$logFile=$this->getLogPath().DIRECTORY_SEPARATOR.$this->getLogFile();
if(@filesize($logFile)>$this->getMaxFileSize()*1024)
$this->rotateFiles();
$fp=@fopen($logFile,'a');
@flock($fp,LOCK_EX);
foreach($logsas$log)
@fwrite($fp,$this->formatLogMessage($log[0],$log[1],$log[2],$log[3]));
@flock($fp,LOCK_UN);
@fclose($fp);
}

保存日志信息在文件中。

rotateFiles() 方法
protected void rotateFiles()
源码: framework/logging/CFileLogRoute.php#153 (显示) protectedfunctionrotateFiles()
{
$file=$this->getLogPath().DIRECTORY_SEPARATOR.$this->getLogFile();
$max=$this->getMaxLogFiles();
for($i=$max;$i>0;--$i)
{
$rotateFile=$file.'.'.$i;
if(is_file($rotateFile))
{
//suppresserrorsbecauseit'spossiblemultipleprocessesenterintothissection
if($i===$max)
@unlink($rotateFile);
else
@rename($rotateFile,$file.'.'.($i+1));
}
}
if(is_file($file))
@rename($file,$file.'.1');//suppresserrorsbecauseit'spossiblemultipleprocessesenterintothissection
}

轮流日志文件。

setLogFile() 方法
public void setLogFile(string $value)
$valuestring日志文件名
源码: framework/logging/CFileLogRoute.php#94 (显示) publicfunctionsetLogFile($value)
{
$this->_logFile=$value;
}
setLogPath() 方法
public void setLogPath(string $value)
$valuestring存储日志文件目录.
源码: framework/logging/CFileLogRoute.php#75 (显示) publicfunctionsetLogPath($value)
{
$this->_logPath=realpath($value);
if($this->_logPath===false||!is_dir($this->_logPath)||!is_writable($this->_logPath))
thrownewCException(Yii::t('yii','CFileLogRoute.logPath"{path}"doesnotpointtoavaliddirectory.MakesurethedirectoryexistsandiswritablebytheWebserverprocess.',
array('{path}'=>$value)));
}
setMaxFileSize() 方法
public void setMaxFileSize(integer $value)
$valueinteger日志文件的最大尺寸(KB)。
源码: framework/logging/CFileLogRoute.php#110 (显示) publicfunctionsetMaxFileSize($value)
{
if(($this->_maxFileSize=(int)$value)<1)
$this->_maxFileSize=1;
}
setMaxLogFiles() 方法
public void setMaxLogFiles(integer $value)
$valueinteger用于轮流的文件数。
源码: framework/logging/CFileLogRoute.php#127 (显示) publicfunctionsetMaxLogFiles($value)
{
if(($this->_maxLogFiles=(int)$value)<1)
$this->_maxLogFiles=1;
}