'ERROR', E_WARNING => 'WARNING', E_PARSE => 'PARSE', E_NOTICE => 'NOTICE', E_CORE_ERROR => 'CORE_ERROR', E_CORE_WARNING => 'CORE_WARNING', E_COMPILE_ERROR => 'COMPILE_ERROR', E_COMPILE_WARNING => 'COMPILE_WARNING', E_USER_ERROR => 'USER_ERROR', E_USER_WARNING => 'USER_WARNING', E_USER_NOTICE => 'USER_NOTICE', E_STRICT => 'STRICT', E_RECOVERABLE_ERROR => 'RECOVERABLE_ERROR', E_DEPRECATED => 'DEPRECATED', E_USER_DEPRECATED => 'USER_DEPRECATED', default => 'UNKNOWN' }; $message = "[$timestamp] PHP $errorType: $errstr in $errfile on line $errline"; error_log($message . PHP_EOL, 3, $logFile); return false; }); set_exception_handler(function($exception) use ($logFile) { $timestamp = date('Y-m-d H:i:s'); $message = "[$timestamp] UNCAUGHT EXCEPTION: " . get_class($exception) . ": " . $exception->getMessage() . " in " . $exception->getFile() . " on line " . $exception->getLine() . "\n" . $exception->getTraceAsString(); error_log($message . PHP_EOL, 3, $logFile); }); register_shutdown_function(function() use ($logFile) { $error = error_get_last(); if ($error && in_array($error['type'], [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR])) { $timestamp = date('Y-m-d H:i:s'); $message = "[$timestamp] FATAL: " . $error['message'] . " in " . $error['file'] . " on line " . $error['line']; error_log($message . PHP_EOL, 3, $logFile); } });