From bbf8bb0bb3f33c92933dfd499b571f56edda4a59 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Wed, 12 Sep 2012 22:30:04 +0300 Subject: [PATCH 1/2] Log PHP errors to the OC log --- lib/base.php | 3 +++ lib/log.php | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/base.php b/lib/base.php index 6b4dd789b2..4ff5a43bd2 100644 --- a/lib/base.php +++ b/lib/base.php @@ -317,6 +317,9 @@ class OC{ self::initPaths(); + register_shutdown_function(array('OC_Log', 'onShutdown')); + set_error_handler(array('OC_Log', 'onError' )); + // set debug mode if an xdebug session is active if (!defined('DEBUG') || !DEBUG) { if(isset($_COOKIE['XDEBUG_SESSION'])) { diff --git a/lib/log.php b/lib/log.php index 8bb2839be6..9c754cf60c 100644 --- a/lib/log.php +++ b/lib/log.php @@ -36,4 +36,21 @@ class OC_Log { $log_class=self::$class; $log_class::write($app, $message, $level); } + + //Fatal errors handler + public static function onShutdown(){ + $error = error_get_last(); + if($error) { + //ob_end_clean(); + self::write('PHP', $error['message'] . ' at ' . $error['file'] . '#' . $error['line'], self::FATAL); + } else { + return true; + } + } + + //Recoverable errors handler + public static function onError($number, $message, $file, $line){ + self::write('PHP', $message . ' at ' . $file . '#' . $line, self::WARN); + + } } From 2b6869bcea2b09357a81ddd299969c47e2b79ada Mon Sep 17 00:00:00 2001 From: VicDeo Date: Wed, 26 Sep 2012 14:38:06 +0300 Subject: [PATCH 2/2] Uncaught exception logging --- lib/base.php | 5 +++-- lib/log.php | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/base.php b/lib/base.php index 4ff5a43bd2..b4b56267c5 100644 --- a/lib/base.php +++ b/lib/base.php @@ -317,8 +317,9 @@ class OC{ self::initPaths(); - register_shutdown_function(array('OC_Log', 'onShutdown')); - set_error_handler(array('OC_Log', 'onError' )); + register_shutdown_function(array('OC_Log', 'onShutdown')); + set_error_handler(array('OC_Log', 'onError')); + set_exception_handler(array('OC_Log', 'onException')); // set debug mode if an xdebug session is active if (!defined('DEBUG') || !DEBUG) { diff --git a/lib/log.php b/lib/log.php index 9c754cf60c..17f781fa91 100644 --- a/lib/log.php +++ b/lib/log.php @@ -47,6 +47,11 @@ class OC_Log { return true; } } + + // Uncaught exception handler + public static function onException($exception){ + self::write('PHP', $exception->getMessage() . ' at ' . $exception->getFile() . '#' . $exception->getLine(), self::FATAL); + } //Recoverable errors handler public static function onError($number, $message, $file, $line){