Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP log: Warning format

The PHP log format does not include the date, for Warnings. For instance

PHP Warning:  Cannot modify header information...

does not have any date of when the warning happened.

Is there a way to change the Warning format, or at least have the date in the log? (usingphp-fpm if it matters).

like image 565
Déjà vu Avatar asked Nov 04 '22 20:11

Déjà vu


1 Answers

You can of course always define your own error handler using set_error_handler. Simplified example:

function handler($errno, $errstr, $errfile, $errline, $errcontext) {
    $message = date('Y-m-d H:i:s') . ": $errstr in $errfile at $errline\n";
    file_put_contents('error.log', $message, FILE_APPEND);
}

set_error_handler('handler');
like image 158
deceze Avatar answered Nov 09 '22 13:11

deceze