【发布时间】:2011-08-11 09:55:49
【问题描述】:
我想重写 CI_Log 类来改进日志行。 我想记录调用类的名称和方法。 示例:
DEBUG - 2011-04-23 09:21:29 - MY_Class - method --> Router Class Initialized
我试图像这样覆盖 write_log 方法:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Log extends CI_Log {
public function write_log($level = 'error', $msg, $php_error = FALSE)
{
[...]
$message .=
$level .
(($level == 'INFO') ? ' - ' : ' - ') .
$this->router->fetch_class() .
' - ' .
$this->router->fetch_method() .
' - ' .
date($this->_date_fmt). ' --> ' .
$msg .
"\n";
[...]
}
}
但它不起作用,$this->router 不可访问。
你能帮帮我吗?
【问题讨论】:
-
当然,
$this->router只适用于控制器,所以这不是一个好主意。我希望这适用于模型等......
标签: php codeigniter logging