Skip to content

Instantly share code, notes, and snippets.

@smartdeal
Created February 21, 2017 16:11
Show Gist options
  • Save smartdeal/871c2228f8da35fb8b5e0471410643f6 to your computer and use it in GitHub Desktop.
Save smartdeal/871c2228f8da35fb8b5e0471410643f6 to your computer and use it in GitHub Desktop.
PHP errors to file
set_error_handler('err_handler');
function err_handler($errno, $errmsg, $filename, $linenum) {
$date = date('Y-m-d H:i:s (T)');
$f = fopen('errors.log', 'a');
if (!empty($f)) {
$filename =str_replace($_SERVER['DOCUMENT_ROOT'],'',$filename);
$err = "$errmsg = $filename = $linenum\r\n";
fwrite($f, $err);
fclose($f);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment