From df4bc01ff82c373f92f4a699862926cfdc324cb4 Mon Sep 17 00:00:00 2001 From: Albert Santoni Date: Mon, 2 Feb 2015 18:03:13 -0500 Subject: [PATCH] Log all PHP errors (including parse errors) to our zend log --- .../controllers/ShowbuilderController.php | 8 ++++ airtime_mvc/application/logging/Logging.php | 45 +++++++++++++++++++ airtime_mvc/public/index.php | 1 + 3 files changed, 54 insertions(+) diff --git a/airtime_mvc/application/controllers/ShowbuilderController.php b/airtime_mvc/application/controllers/ShowbuilderController.php index 9abbeb167..189ef2aa8 100644 --- a/airtime_mvc/application/controllers/ShowbuilderController.php +++ b/airtime_mvc/application/controllers/ShowbuilderController.php @@ -283,6 +283,14 @@ class ShowbuilderController extends Zend_Controller_Action $mediaItems = $request->getParam("mediaIds", array()); $scheduledItems = $request->getParam("schedIds", array()); + $log_vars = array(); + $log_vars["url"] = $_SERVER['HTTP_HOST']; + $log_vars["action"] = "showbuilder/schedule-add"; + $log_vars["params"] = array(); + $log_vars["params"]["media_items"] = $mediaItems; + $log_vars["params"]["scheduled_items"] = $scheduledItems; + Logging::info($log_vars); + try { $scheduler = new Application_Model_Scheduler(); $scheduler->scheduleAfter($scheduledItems, $mediaItems); diff --git a/airtime_mvc/application/logging/Logging.php b/airtime_mvc/application/logging/Logging.php index d49c94238..a32aa9410 100644 --- a/airtime_mvc/application/logging/Logging.php +++ b/airtime_mvc/application/logging/Logging.php @@ -123,4 +123,49 @@ class Logging { Propel::setLogger(null); } + public static function loggingShutdownCallback() + { + //Catch the types of errors that PHP doesn't normally let us catch and + //would otherwise log to the apache log. We route these to our Airtime log to improve the modularity + //and reliability of our error logging. (All errors are in one spot!) + $err = error_get_last(); + if (!is_array($err) || !array_key_exists('type', $err)) { + return; + } + + switch($err['type']) + { + case E_ERROR: + case E_PARSE: + case E_CORE_ERROR: + case E_CORE_WARNING: + case E_COMPILE_ERROR: + case E_COMPILE_WARNING: + //error_log("Oh noes, a fatal: " . var_export($err, true), 1, 'fatals@example.com'); + $errorStr = ''; + if (array_key_exists('message', $err)) { + $errorStr .= $err['message']; + } + if (array_key_exists('file', $err)) + { + $errorStr .= ' at ' .$err['file']; + } + if (array_key_exists('line', $err)) + { + $errorStr .= ':' . $err['line']; + } + + $errorStr .= "\n" . var_export($err, true); + Logging::error($errorStr); + break; + } + } + + public static function setupParseErrorLogging() + { + //Static callback: + register_shutdown_function('Logging::loggingShutdownCallback'); + } + } + diff --git a/airtime_mvc/public/index.php b/airtime_mvc/public/index.php index a82aceef8..e7a579ba3 100644 --- a/airtime_mvc/public/index.php +++ b/airtime_mvc/public/index.php @@ -63,6 +63,7 @@ $application = new Zend_Application( require_once (APPLICATION_PATH."/logging/Logging.php"); Logging::setLogPath('/var/log/airtime/zendphp.log'); +Logging::setupParseErrorLogging(); // Create application, bootstrap, and run try {