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 鎸囧畾淇濇寔澶氬皯涓枃浠.
鏃ュ織鏂囦欢琚瓨鍌ㄥ湪 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
灞炴
鏃ュ織鏂囦欢鍚嶃傞粯璁ゆ槸鈥榓pplication.log鈥欍
logPath
灞炴
瀛樺偍鏃ュ織鏂囦欢鐩綍銆傞粯璁ゆ槸搴旂敤绋嬪簭 runtime 璺緞銆
maxFileSize
灞炴
鏈澶ф棩蹇楁枃浠跺昂瀵(KB)銆傞粯璁ゆ槸1024 (1MB)銆
maxLogFiles
灞炴
杞祦鐨勬枃浠舵暟銆傞粯璁ゆ槸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;
}