Log all PHP errors (including parse errors) to our zend log

This commit is contained in:
Albert Santoni 2015-02-02 18:03:13 -05:00
parent 163227439c
commit df4bc01ff8
3 changed files with 54 additions and 0 deletions

View File

@ -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);

View File

@ -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');
}
}

View File

@ -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 {