Is it possible to change PHP error log output? -
i'm configured error_log directive in php.ini file, this:
error_log = /path/to/logs/error_log and then, configured error_reporting directive this:
error_reporting = e_all & ~e_deprecated & ~e_strict when check error_log file, see normal php warning/error text lines:
[03-jun-2015 08:39:00 america/bogota] php notice: undefined index: cerrar in /fake/path/to/file2.php on line 68 [03-jun-2015 08:40:49 america/bogota] php notice: undefined index: in /fake/path/to/file2.php on line 344 the question is: there way change output format?, mean, if can print, example, ip , subdomain cause warning.
i looking in stackoverflow, in google, , don't find clear information or examples.
thank help.
so agreeing && finalizing comments given above best approach set_error_handler.
wrote class you. set_exception_handler have unified experience , save errors in error::$throwables display them on shutdown instead of view (handled view class not provided here).
class error { public static $error_types = array( e_error => 'e_error', e_warning => 'e_warning', e_parse => 'e_parse', e_notice => 'e_notice', e_core_error => 'e_core_error', e_core_warning => 'e_core_warning', e_compile_error => 'e_compile_error', e_compile_warning => 'e_compile_warning', e_user_error => 'e_user_error', e_user_warning => 'e_user_warning', e_user_notice => 'e_user_notice', e_strict => 'e_strict', e_recoverable_error => 'e_recoverable_error', e_deprecated => 'e_deprecated', e_user_deprecated => 'e_user_deprecated' ); public static $shutdown = false; public static $throwables = array(); public static function set_throwable_handlers() { ini_set('error_reporting', e_all & ~e_deprecated & ~e_strict); ini_set('display_errors', false); ini_set('log_errors', true); ini_set('error_log', '/path/to/logs/error_log'); set_error_handler(array('error', 'error_handler')); set_exception_handler(array('error', 'exception_handler')); register_shutdown_function(array('error', 'shutdown_handler')); } public static function set_throwable($error_number, $error_text, $error_file, $error_line, $error_log = true) { if ($error_log === true) { //provide data want log error log error_log('php '.self::$error_types[$error_number].' : '.$error_text.' in '.$error_file.' on line '.$error_line); } //provide data want class variable self::$throwables[$error_number][] = array('type' => self::$error_types[$error_number], 'text' => $error_text, 'file' => $error_file, 'line' => $error_line); } public static function exception_handler(exception $exception) { self::set_throwable($exception->getcode(), $exception->getmessage(), $exception->getfile(), $exception->getline()); } public static function error_handler($error_number = '', $error_text = '', $error_file = '', $error_line = '') { self::set_throwable($error_number, $error_text, $error_file, $error_line); } public static function shutdown_handler() { $error = error_get_last(); if ($error !== null) { self::set_throwable($error['type'], $error['message'], $error['file'], $error['line'], false); } //enables error page on shutdown & displays throwables //self::$shutdown = true; // //view::display(); } public static function throw_error($error_text, $error_number = e_user_notice) { trigger_error($error_text, $error_number); exit; } }
Comments
Post a Comment