Last active
August 29, 2015 14:16
-
-
Save ursuleacv/0a24821e0b6694a389bb to your computer and use it in GitHub Desktop.
Yii Framework : format log message - add ip address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class YourFileLogRoute extends CFileLogRoute | |
{ | |
protected function formatLogMessage($message,$level,$category,$time) | |
{ | |
return @date('Y/m/d H:i:s',$time)." [". Yii::app()->request->userHostAddress."]"." [$level] [$category] $message\n"; | |
} | |
} | |
# Do not insert 404 error in logs file | |
# http://www.yiiframework.com/forum/index.php?/topic/22510-no-route-chttpexception/page__p__110030__fromsearch__1#entry110030 | |
class MyLogFilter extends CLogFilter { | |
public function filter(&$logs) | |
{ | |
$mylogs = array() | |
foreach($logs as $log) | |
{ | |
//var_dump($log); | |
//$log[2] should be the category | |
if(strpos($log[2],'exception.CHttpException') === false) | |
$mylogs[]=$log; | |
} | |
$logs = $mylogs; | |
parent::filter($logs); | |
} | |
'log' => array( | |
'class'=>'YourFileLogRoute', | |
'routes'=>array( | |
array( | |
'class' => 'CFileLogRoute', | |
'levels' => CLogger::LEVEL_ERROR, | |
'logFile' => 'error.log', | |
), | |
array( | |
'class' => 'CFileLogRoute', | |
'levels' => CLogger::LEVEL_WARNING, | |
'logFile' => 'warning.log', | |
), | |
array( | |
'class' => 'CFileLogRoute', | |
'levels' => CLogger::LEVEL_INFO, | |
'logFile' => 'info.log ', | |
), | |
array( | |
'class' => 'CWebLogRoute', | |
'categories' => 'example', | |
'levels' => CLogger::LEVEL_PROFILE, | |
'showInFireBug' => true, | |
'ignoreAjaxInFireBug' => true, | |
), | |
array( | |
'class' => 'CWebLogRoute', | |
'categories' => 'example', | |
), | |
), | |
), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment