Yii我如何看到,在Yii日志文件中记录字符串的代码的哪一部分?
发布于 2012-01-16 07:39:50
它位于index.php (或您正在使用的任何条目文件)中,添加以下行:
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',2);在create application调用之前添加到文件。
将末尾的数字更改为堆栈跟踪中所需的行数。
唯一真正的限制是它出现在每条日志消息上,没有办法过滤。
发布于 2012-01-13 15:42:51
我还没有尝试过,但是您可以更新或扩展CLogger->log()方法,以便在日志消息中添加一些回溯信息,例如,
public function log($message,$level='info',$category='application')
{
$e = new Exception;
$message .= $e->getTraceAsString();
$this->_logs[]=array($message,$level,$category,microtime(true));
$this->_logCount++;
if($this->autoFlush>0 && $this->_logCount>=$this->autoFlush && !$this->_processing)
{
$this->_processing=true;
$this->flush($this->autoDump);
$this->_processing=false;
}
}因此,现在每个日志行都包含一个回溯跟踪。
有关获取“backtrace”或“callstack”的更多信息,请阅读此post - Print PHP Call Stack
如果这里有什么问题,请纠正我。
发布于 2012-01-14 07:37:59
我不确定我是否理解了您的问题,但是跟踪日志(protected/runtime/trace.log)已经指出了Yii::app()->trace()调用所在的文件名(第#行),如下面的示例日志记录:
2012/01/11 12:54:28 [trace] [system.db.CDbCommand] Querying SQL: SELECT * FROM `folks` `f` WHERE `f`.`idfolks` IS NULL LIMIT 1
in /home/hobs/src/appname/protected/controllers/SiteController.php (970)
in /home/hobs/src/appname/index.php (14)假设您已经在protected/config/main.php中设置了跟踪日志路由器...
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'trace', //, info, error, warning', // empty means all levels = default
//'categories'=>'',//'application',// system.*', // default = empty = all categories
'logFile'=>'trace.log',
),
...https://stackoverflow.com/questions/8846922
复制相似问题