下面是一些代碼,你能適應您的需要(我建議創建一個My_Log,而不是編輯,以防萬一CI做系統文件永遠得到更新)。我有這個原因很複雜,並沒有什麼用處,但它可能會給你一個開始:
protected function log_query ($query, $type)
{
$backtrace = debug_backtrace();
$backtrace = array_slice ($backtrace, 2, -2); // first and last two elements are things that never change
$traced = array();
foreach ($backtrace as $bt)
{
$func = isset ($bt['function']) ? $bt['function'].'()' : '';
$line = isset ($bt['line']) ? $bt['line'] : '';
$file = isset ($bt['file']) ? str_replace (APP, '', $bt['file']) : '';
$object = isset ($bt['object']) ? get_class ($bt['object']) : '';
$args = array(); build_args ($bt['args'], $args);
$args = implode ('; ', $args);
if ($object)
{
$obj_func = $object . '->' . $func;
} else {
$obj_func = $func;
}
$traced[] = "$file $obj_func $line $args";
unset($args);
}
$traced = implode ("\n\t", $traced);
$date = MYSQL_DATE_TIME;
$uri = isset ($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '' ;
$query= preg_replace ("/[\n\t]/", ' ', $query);
log_message ('error', "{$query}\n\n\t{$date} ({$type})\n\t{$uri}\n\t{$traced}\n--------------------------\n");
}
謝謝,這證實了我的方向是合理的! – Chords 2014-09-24 14:13:30