sintonia/airtime_mvc/application/logging/Logging.php

73 lines
2.0 KiB
PHP
Raw Normal View History

<?php
class Logging {
private static $_logger;
private static $_path;
public static function getLogger()
2012-08-08 06:08:46 +02:00
{
if (!isset(self::$_logger)) {
$writer = new Zend_Log_Writer_Stream(self::$_path);
2012-08-08 06:08:46 +02:00
if (Zend_Version::compareVersion("1.11") > 0) {
//Running Zend version 1.10 or lower. Need to instantiate our
//own Zend Log class with backported code from 1.11.
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;
}
2012-08-08 06:08:46 +02:00
public static function setLogPath($path)
{
self::$_path = $path;
}
2012-08-08 06:08:46 +02:00
public static function toString($p_msg)
{
if (is_array($p_msg) || is_object($p_msg)) {
2012-04-13 22:50:54 +02:00
return print_r($p_msg, true);
} else {
return $p_msg;
}
}
2012-08-22 00:41:56 +02:00
public static function info($p_msg)
2012-08-08 06:08:46 +02:00
{
$bt = debug_backtrace();
2012-08-08 06:08:46 +02:00
$caller = array_shift($bt);
2012-08-08 06:08:46 +02:00
$file = basename($caller['file']);
$line = $caller['line'];
2012-08-08 06:08:46 +02:00
$caller = array_shift($bt);
$function = $caller['function'];
$logger = self::getLogger();
2012-08-08 06:08:46 +02:00
$logger->info("[$file : $function() : line $line] - ".self::toString($p_msg));
}
2012-08-08 06:08:46 +02:00
public static function debug($p_msg)
{
$bt = debug_backtrace();
2012-08-08 06:08:46 +02:00
$caller = array_shift($bt);
2012-08-08 06:08:46 +02:00
$file = basename($caller['file']);
$line = $caller['line'];
$caller = array_shift($bt);
$function = $caller['function'];
2012-08-08 06:08:46 +02:00
if (defined('APPLICATION_ENV') && APPLICATION_ENV == "development") {
$logger = self::getLogger();
2012-08-08 06:08:46 +02:00
$logger->debug("[$file : $function() : line $line] - ".self::toString($p_msg));
}
}
}