Codeigniter不会在错误日志中记录所有文件名

时间:2017-04-27 11:35:14

标签: php codeigniter error-logging

我使用此配置记录错误

$config['log_threshold'] = 1;

问题是某些错误不包括像这样的文件名,而其他错误包括文件名

ERROR - 2017-04-27 14:20:16 --> Query error: You have an error in your SQL syntax; check the 
manual that corresponds to your MySQL server version for the right syntax to use near 
'ORDER BY `id` DESC' at line 4 - Invalid query: SELECT COUNT(*) AS `numrows` FROM `orders`
WHERE `id` > ORDER BY `id` DESC

ERROR - 2017-04-27 14:20:16 --> Severity: Error --> Call to a member function num_rows() on 
boolean /home/username/public_html/system/database/DB_query_builder.php 1391

为什么会发生这种情况以及如何解决这个问题。我找到了这个答案Codeigniter error log not including file name但找不到'MY_Log.php'

1 个答案:

答案 0 :(得分:0)

我看到了答案:Codeigniter error log not including file name非常清楚。遵循以下步骤:

  1. MY_Log.php文件夹中创建MY_Log.php个文件(请记住MY_log.php而非application/core或其他内容)。
  2. 复制以下代码段并粘贴到该文件中:

    类MY_Log扩展了CI_Log {

    public function write_log($level, $msg)
    {
        foreach (debug_backtrace() as $call)
        {
            // Somehow find the appropriate call here ...
            if ( ! (/* condition to ignore error-handling calls */))
            {
                break;
            }
    
            $msg = '['.$call['file'].'] '.$msg;
            break;
        }
    
        return parent::write_log($level, $msg);
    }
    

    }

  3. 保存文件。完成!