Yii Framework v1.1.10 绫诲弬鑰

CFileLogRoute

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(鐢╧ilo-bytes), 灏嗚繘琛屼竴娆″惊鐜 ,杩欏皢閫氳繃缁欐枃浠跺悕鍔犲墠缂鈥.1鈥欐潵閲嶅懡鍚嶅綋鍓嶆棩蹇楁枃浠躲 鎵鏈夊凡缁忓瓨鍦ㄧ殑鏃ュ織鏂囦欢琚Щ鍔ㄥ埌鍚戝悗鐨勪竴涓綅缃紝 渚嬪锛屸.2鈥 鍒扳.3鈥欙紝鈥.1鈥欙紝鈥樺埌鈥欙紝鈥.2鈥欍 灞炴 maxLogFiles 鎸囧畾淇濇寔澶氬皯涓枃浠.

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
categories string 琚楀彿鎴栫┖鏍煎垎闅旂殑绫诲埆鍒楄〃銆傞粯璁や负绌猴紝鎰忓懗鐫鎵鏈夌被鍒 CLogRoute
enabled boolean 鏄惁鍚敤杩欎釜鏃ュ織璺敱銆傞粯璁や负true銆 CLogRoute
filter mixed 闄勫姞杩囨护鍣 (渚嬪 CLogFilter) 瀹冭搴旂敤鍒版棩蹇椾俊鎭 杩欎釜灞炴х殑鍊艰浼犻掑埌 Yii::createComponent 鍒涘缓涓涓棩蹇楄繃婊ゅ櫒瀵硅薄銆 缁撴灉锛岃繖鍙兘鏄竴涓〃绀鸿繃婊ゅ櫒绫诲悕鐨勫瓧绗︿覆鎴栦竴涓〃绀鸿繃婊ゅ櫒閰嶇疆鐨勬暟缁勩

鎬讳箣锛屾棩蹇楄繃婊ゅ櫒绫诲簲璇ユ槸 CLogFilter 鎴栧畠鐨勪竴涓瓙绫汇 榛樿涓簄ull锛屾剰鍛崇潃娌℃湁杩囨护鍣ㄨ浣跨敤銆
CLogRoute
levels string 鐢ㄩ楀彿鎴栫┖鏍煎垎闅旂殑绛夌骇鍒楄〃銆傞粯璁ゆ槸绌猴紝鎰忓懗鐫鎵鏈夌瓑绾с CLogRoute
logFile string 鏃ュ織鏂囦欢鍚嶃傞粯璁ゆ槸鈥榓pplication. CFileLogRoute
logPath string 瀛樺偍鏃ュ織鏂囦欢鐩綍銆傞粯璁ゆ槸搴旂敤绋嬪簭 runtime 璺緞銆 CFileLogRoute
logs array 鍒扮洰鍓嶄负姝㈣繖涓棩蹇楄矾鐢辨悳闆嗙殑鏃ュ織銆 CLogRoute
maxFileSize integer 鏈澶ф棩蹇楁枃浠跺昂瀵(KB)銆傞粯璁ゆ槸1024 (1MB)銆 CFileLogRoute
maxLogFiles integer 杞祦鐨勬枃浠舵暟銆傞粯璁ゆ槸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() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getLogFile() 杩斿洖鏃ュ織鏂囦欢鍚嶃傞粯璁ゆ槸鈥榓pplication.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)

鏃ュ織鏂囦欢鍚嶃傞粯璁ゆ槸鈥榓pplication.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 鏃ュ織鏂囦欢鍚嶃傞粯璁ゆ槸鈥榓pplication.log鈥欍
婧愮爜锛 framework/logging/CFileLogRoute.php#86 (鏄剧ず)
public function getLogFile()
{
    return 
$this->_logFile;
}

getLogPath() 鏂规硶
public string getLogPath()
{return} string 瀛樺偍鏃ュ織鏂囦欢鐩綍銆傞粯璁ゆ槸搴旂敤绋嬪簭 runtime 璺緞銆
婧愮爜锛 framework/logging/CFileLogRoute.php#66 (鏄剧ず)
public function getLogPath()
{
    return 
$this->_logPath;
}

getMaxFileSize() 鏂规硶
public integer getMaxFileSize()
{return} integer 鏈澶ф棩蹇楁枃浠跺昂瀵(KB)銆傞粯璁ゆ槸1024 (1MB)銆
婧愮爜锛 framework/logging/CFileLogRoute.php#102 (鏄剧ず)
public function getMaxFileSize()
{
    return 
$this->_maxFileSize;
}

getMaxLogFiles() 鏂规硶
public integer getMaxLogFiles()
{return} integer 杞祦鐨勬枃浠舵暟銆傞粯璁ゆ槸5銆
婧愮爜锛 framework/logging/CFileLogRoute.php#119 (鏄剧ず)
public function getMaxLogFiles()
{
    return 
$this->_maxLogFiles;
}

init() 鏂规硶
public void init()
婧愮爜锛 framework/logging/CFileLogRoute.php#56 (鏄剧ず)
public function init()
{
    
parent::init();
    if(
$this->getLogPath()===null)
        
$this->setLogPath(Yii::app()->getRuntimePath());
}

鍒濆鍖栨璺敱銆 杩欎釜鏂规硶琚彂璧峰湪璺敱绠$悊鍣ㄥ垱寤烘璺敱涔嬪悗銆

processLogs() 鏂规硶
protected void processLogs(array $logs)
$logs array 鏃ュ織淇℃伅鍒楄〃
婧愮爜锛 framework/logging/CFileLogRoute.php#137 (鏄剧ず)
protected function processLogs($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(
$logs as $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 (鏄剧ず)
protected function rotateFiles()
{
    
$file=$this->getLogPath().DIRECTORY_SEPARATOR.$this->getLogFile();
    
$max=$this->getMaxLogFiles();
    for(
$i=$max;$i>0;--$i)
    {
        
$rotateFile=$file.'.'.$i;
        if(
is_file($rotateFile))
        {
            
// suppress errors because it's possible multiple processes enter into this section
            
if($i===$max)
                @
unlink($rotateFile);
            else
                @
rename($rotateFile,$file.'.'.($i+1));
        }
    }
    if(
is_file($file))
        @
rename($file,$file.'.1'); // suppress errors because it's possible multiple processes enter into this section
}

杞祦鏃ュ織鏂囦欢銆

setLogFile() 鏂规硶
public void setLogFile(string $value)
$value string 鏃ュ織鏂囦欢鍚
婧愮爜锛 framework/logging/CFileLogRoute.php#94 (鏄剧ず)
public function setLogFile($value)
{
    
$this->_logFile=$value;
}

setLogPath() 鏂规硶
public void setLogPath(string $value)
$value string 瀛樺偍鏃ュ織鏂囦欢鐩綍.
婧愮爜锛 framework/logging/CFileLogRoute.php#75 (鏄剧ず)
public function setLogPath($value)
{
    
$this->_logPath=realpath($value);
    if(
$this->_logPath===false || !is_dir($this->_logPath) || !is_writable($this->_logPath))
        throw new 
CException(Yii::t('yii','CFileLogRoute.logPath "{path}" does not point to a valid directory. Make sure the directory exists and is writable by the Web server process.',
            array(
'{path}'=>$value)));
}

setMaxFileSize() 鏂规硶
public void setMaxFileSize(integer $value)
$value integer 鏃ュ織鏂囦欢鐨勬渶澶у昂瀵(KB)銆
婧愮爜锛 framework/logging/CFileLogRoute.php#110 (鏄剧ず)
public function setMaxFileSize($value)
{
    if((
$this->_maxFileSize=(int)$value)<1)
        
$this->_maxFileSize=1;
}

setMaxLogFiles() 鏂规硶
public void setMaxLogFiles(integer $value)
$value integer 鐢ㄤ簬杞祦鐨勬枃浠舵暟銆
婧愮爜锛 framework/logging/CFileLogRoute.php#127 (鏄剧ず)
public function setMaxLogFiles($value)
{
    if((
$this->_maxLogFiles=(int)$value)<1)
        
$this->_maxLogFiles=1;
}

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.