Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Yii框架上定制日志文件?_Php_Logging_Yii_Logfiles - Fatal编程技术网

Php 如何在Yii框架上定制日志文件?

Php 如何在Yii框架上定制日志文件?,php,logging,yii,logfiles,Php,Logging,Yii,Logfiles,我正在尝试处理我网站上的错误。我将每个错误记录在日志文件中,但我想知道如何自定义记录在日志文件中的消息 现在,我得到了这个信息: 2013/09/30 10:08:59[错误][异常.CException]异常 “CException”中包含消息“错误测试” myDomain.com\protected\controllers\SiteController.php:234 您能帮助我吗?对于手动自定义日志消息,您需要创建自己的LogRoute类。在您的情况下,您需要从CFileLogRoute继

我正在尝试处理我网站上的错误。我将每个错误记录在日志文件中,但我想知道如何自定义记录在日志文件中的消息

现在,我得到了这个信息:

2013/09/30 10:08:59[错误][异常.CException]异常 “CException”中包含消息“错误测试” myDomain.com\protected\controllers\SiteController.php:234


您能帮助我吗?

对于手动自定义日志消息,您需要创建自己的LogRoute类。在您的情况下,您需要从CFileLogRoute继承类并重写formatLogMessage方法(例如示例):

然后配置配置文件:


是的,@ragingprodigy是正确的:您可以在index.php中设置
define('YII_DEBUG',0)
define('yi_TRACE_LEVEL',0)
来从日志消息中删除堆栈跟踪

您可以使用YII::log($message,$LEVEL,$category);谢谢你的回答,但我还有一个问题。如何删除“堆栈跟踪”?我认为您可以修改这行
defined('yi_trace_LEVEL')或define('yi_trace_LEVEL',3)
index.php
文件中
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/',
               ),
               ...