dongzhan7253 2017-02-17 22:10
浏览 48
已采纳

PHP错误日志 - php.ini php错误的唯一文件

I'm currently working on a project and to give a helping hand, I've changed my php.ini file to log errors to "php_errors.log" inside the directory of where a PHP file has returned an error.

I was wondering, after searching online (maybe I'm not wording this correctly), is there any way to set a unique file name in the php.ini file for the different errors.

For example, if an error occurred on let's say account.php, is there any way to log an error file "account_php_errors.log" through the ini file?

  • 写回答

4条回答 默认 最新

  • douzhui8531 2017-02-17 22:26
    关注

    You can create a custom error handler within the application. You should be able to get all the needed details from here

    // error handler function
    function myErrorHandler($errno, $errstr, $errfile, $errline) {
     // file_put_contents
    }
    
    set_error_handler("myErrorHandler");
    

    More info: http://php.net/manual/en/function.set-error-handler.php

    I would rethink the purpose for keeping errors logs in different directories, because it will make Your app messy. Greping logs from different folders alone is not so convienient and if You ever want to add log monitoring tools like Logstash with elasticsearch, you will be forced to do a more complex setup

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?