diff --git a/airtime_mvc/application/controllers/ScheduleController.php b/airtime_mvc/application/controllers/ScheduleController.php index 99a17f19a..6102c075f 100644 --- a/airtime_mvc/application/controllers/ScheduleController.php +++ b/airtime_mvc/application/controllers/ScheduleController.php @@ -136,7 +136,6 @@ class ScheduleController extends Zend_Controller_Action $editable = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); $calendar_interval = Application_Model_Preference::GetCalendarTimeScale(); - Logging::info($calendar_interval); if ($calendar_interval == "agendaDay") { list($start, $end) = Application_Model_Show::getStartEndCurrentDayView(); } else if ($calendar_interval == "agendaWeek") { diff --git a/airtime_mvc/application/logging/Logging.php b/airtime_mvc/application/logging/Logging.php index 6ca2cca84..d49c94238 100644 --- a/airtime_mvc/application/logging/Logging.php +++ b/airtime_mvc/application/logging/Logging.php @@ -38,52 +38,50 @@ class Logging { return $p_msg; } } + + /** @param debugMode Prints the function name, file, and line number. This is slow as it uses debug_backtrace() + * so don't use it unless you need it. + */ + private static function getLinePrefix($debugMode=false) + { + $linePrefix = ""; + + if (array_key_exists('SERVER_NAME', $_SERVER)) { + $linePrefix .= $_SERVER['SERVER_NAME'] . " "; + } + + if ($debugMode) { + //debug_backtrace is SLOW so we don't want this invoke unless there was a real error! (hence $debugMode) + $bt = debug_backtrace(); + $caller = $bt[1]; + $file = basename($caller['file']); + $line = $caller['line']; + $function = "Unknown function"; + if (array_key_exists(2, $bt)) { + $function = $bt[2]['function']; + } + $linePrefix .= "[$file:$line - $function()] - "; + } + + return $linePrefix; + } public static function info($p_msg) { - $bt = debug_backtrace(); - - $caller = array_shift($bt); - $file = basename($caller['file']); - $line = $caller['line']; - - $caller = array_shift($bt); - $function = $caller['function']; - $logger = self::getLogger(); - $logger->info($_SERVER['SERVER_NAME'] . " [$file : $function() : line $line] - ".self::toString($p_msg)); + $logger->info(self::getLinePrefix() . self::toString($p_msg)); } public static function warn($p_msg) { - $bt = debug_backtrace(); - - $caller = array_shift($bt); - $file = basename($caller['file']); - $line = $caller['line']; - - $caller = array_shift($bt); - $function = $caller['function']; - $logger = self::getLogger(); - $logger->warn($_SERVER['SERVER_NAME'] . " [$file : $function() : line $line] - " - . self::toString($p_msg)); + $logger->warn(self::getLinePrefix() . self::toString($p_msg)); } public static function error($p_msg) { - $bt = debug_backtrace(); - - $caller = array_shift($bt); - $file = basename($caller['file']); - $line = $caller['line']; - - $caller = array_shift($bt); - $function = $caller['function']; - $logger = self::getLogger(); - $logger->err($_SERVER['SERVER_NAME'] . " [$file : $function() : line $line] - " - . self::toString($p_msg)); + $logger->err(self::getLinePrefix(true) . self::toString($p_msg)); } public static function debug($p_msg) @@ -92,17 +90,8 @@ class Logging { return; } - $bt = debug_backtrace(); - - $caller = array_shift($bt); - $file = basename($caller['file']); - $line = $caller['line']; - - $caller = array_shift($bt); - $function = $caller['function']; - $logger = self::getLogger(); - $logger->debug($_SERVER['SERVER_NAME'] . " [$file : $function() : line $line] - ".self::toString($p_msg)); + $logger->debug(self::getLinePrefix(true) . self::toString($p_msg)); } // kind of like debug but for printing arrays more compactly (skipping // empty elements diff --git a/airtime_mvc/public/index.php b/airtime_mvc/public/index.php index 5fcfa36d7..59a4054d7 100644 --- a/airtime_mvc/public/index.php +++ b/airtime_mvc/public/index.php @@ -74,15 +74,19 @@ try { $application->bootstrap()->run(); } } catch (Exception $e) { - echo $e->getMessage(); - echo "
"; - echo $e->getTraceAsString(); - echo ""; - Logging::info($e->getMessage()); + + header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500); + + Logging::error($e->getMessage()); if (VERBOSE_STACK_TRACE) { - Logging::info($e->getTraceAsString()); + echo $e->getMessage(); + echo "
"; + echo $e->getTraceAsString(); + echo ""; + Logging::error($e->getTraceAsString()); } else { - Logging::info($e->getTrace()); + Logging::error($e->getTrace()); } + die(); }