123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- class Logging {
- private static $_logger;
- private static $_path;
- public static function getLogger()
- {
- if (!isset(self::$_logger)) {
- $writer = new Zend_Log_Writer_Stream(self::$_path);
-
- if (Zend_Version::compareVersion("1.11") > 0) {
-
-
- require_once __DIR__."/AirtimeLog.php";
- self::$_logger = new Airtime_Zend_Log($writer);
- } else {
- self::$_logger = new Zend_Log($writer);
- }
- self::$_logger->registerErrorHandler();
- }
- return self::$_logger;
- }
- public static function setLogPath($path)
- {
- self::$_path = $path;
- }
-
- public static function toString($p_msg)
- {
- if (is_array($p_msg) || is_object($p_msg)) {
- return print_r($p_msg, true);
- } else if (is_bool($p_msg)) {
- return $p_msg ? "true" : "false";
- } else {
- return $p_msg;
- }
- }
-
- private static function getLinePrefix($debugMode=false)
- {
- $linePrefix = "";
- if (array_key_exists('SERVER_NAME', $_SERVER)) {
- $linePrefix .= $_SERVER['SERVER_NAME'] . " ";
- }
- if ($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)
- {
- $logger = self::getLogger();
- $logger->info(self::getLinePrefix() . self::toString($p_msg));
- }
- public static function warn($p_msg)
- {
- $logger = self::getLogger();
- $logger->warn(self::getLinePrefix() . self::toString($p_msg));
- }
- public static function error($p_msg)
- {
- $logger = self::getLogger();
- $logger->err(self::getLinePrefix(true) . self::toString($p_msg));
- }
-
- public static function debug($p_msg)
- {
- if (!(defined('APPLICATION_ENV') && APPLICATION_ENV == "development")) {
- return;
- }
- $logger = self::getLogger();
- $logger->debug(self::getLinePrefix(true) . self::toString($p_msg));
- }
-
-
- public static function debug_sparse(array $p_msg)
- {
- Logging::debug("Sparse output:");
- Logging::debug( array_filter($p_msg) );
- }
- public static function enablePropelLogging()
- {
- $logger = Logging::getLogger();
- Propel::setLogger($logger);
- $con = Propel::getConnection();
- $con->useDebug(true);
- $config = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT);
- $config->setParameter('debugpdo.logging.details.method.enabled', true);
- $config->setParameter('debugpdo.logging.details.time.enabled', true);
- $config->setParameter('debugpdo.logging.details.mem.enabled', true);
- }
- public static function disablePropelLogging()
- {
- $con = Propel::getConnection();
- $con->useDebug(false);
- Propel::setLogger(null);
- }
- public static function loggingShutdownCallback()
- {
-
-
-
- $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:
-
- $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()
- {
-
- register_shutdown_function('Logging::loggingShutdownCallback');
- }
- }
|