我正在尝试处理我的网站上的错误。我将每个错误记录在日志文件中,但我想知道如何自定义日志文件中记录的消息。
现在,我收到此消息:
2013/09/30 10:08:59 [error] [exception.CException] exception 'CException' with message 'Error test' in myDomain.com\protected\controllers\SiteController.php:234
你能帮我吗?
最佳答案
对于手动自定义日志消息,您需要创建自己的 LogRoute 类。在您的情况下,您需要从 CFileLogRoute 继承类并覆盖方法 formatLogMessage (例如示例):
class MyFileLogRoute extends CFileLogRoute{ protected function formatLogMessage($message,$level,$category,$time) { //enter code here your custom message format return @date('Y/m/d H:i:s',$time)." [$level] [$category] $message\n"; } }
配置你的配置文件:
'log' => array( 'class' => 'CLogRouter', 'routes' => array( array( 'class' => 'MyFileLogRoute', 'levels' => 'error, warning, info', 'categories' => 'application.*', 'logPath' => dirname(__FILE__).'/../../../../../logs/', ), ...
是的,@ragingprodigy 是对的:您可以在 index.php 中设置 define('YII_DEBUG', 0)
或 define('YII_TRACE_LEVEL', 0)
来从日志消息中删除堆栈跟踪
关于php - 如何在 Yii 框架上自定义日志文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19091896/