slightly improved PHP logging format
This commit is contained in:
parent
d9e8e7d4cb
commit
333c8ec211
1 changed files with 28 additions and 10 deletions
|
@ -5,7 +5,8 @@ class Logging {
|
||||||
private static $_logger;
|
private static $_logger;
|
||||||
private static $_path;
|
private static $_path;
|
||||||
|
|
||||||
public static function getLogger(){
|
public static function getLogger()
|
||||||
|
{
|
||||||
if (!isset(self::$_logger)) {
|
if (!isset(self::$_logger)) {
|
||||||
$writer = new Zend_Log_Writer_Stream(self::$_path);
|
$writer = new Zend_Log_Writer_Stream(self::$_path);
|
||||||
|
|
||||||
|
@ -22,11 +23,13 @@ class Logging {
|
||||||
return self::$_logger;
|
return self::$_logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setLogPath($path){
|
public static function setLogPath($path)
|
||||||
|
{
|
||||||
self::$_path = $path;
|
self::$_path = $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function toString($p_msg){
|
public static function toString($p_msg)
|
||||||
|
{
|
||||||
if (is_array($p_msg) || is_object($p_msg)) {
|
if (is_array($p_msg) || is_object($p_msg)) {
|
||||||
return print_r($p_msg, true);
|
return print_r($p_msg, true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -34,21 +37,36 @@ class Logging {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function log($p_msg){
|
public static function log($p_msg)
|
||||||
|
{
|
||||||
$bt = debug_backtrace();
|
$bt = debug_backtrace();
|
||||||
|
|
||||||
$caller = array_shift($bt);
|
$caller = array_shift($bt);
|
||||||
|
$file = basename($caller['file']);
|
||||||
|
$line = $caller['line'];
|
||||||
|
|
||||||
|
$caller = array_shift($bt);
|
||||||
|
$function = $caller['function'];
|
||||||
|
|
||||||
$logger = self::getLogger();
|
$logger = self::getLogger();
|
||||||
$logger->info(self::toString($p_msg)." - file:".$caller['file'].":".$caller['line']);
|
$logger->info("[$file : $function() : line $line] - ".self::toString($p_msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function debug($p_msg){
|
public static function debug($p_msg)
|
||||||
|
{
|
||||||
$bt = debug_backtrace();
|
$bt = debug_backtrace();
|
||||||
|
|
||||||
$caller = array_shift($bt);
|
$caller = array_shift($bt);
|
||||||
|
$file = basename($caller['file']);
|
||||||
|
$line = $caller['line'];
|
||||||
|
|
||||||
|
$caller = array_shift($bt);
|
||||||
|
$function = $caller['function'];
|
||||||
|
|
||||||
|
|
||||||
if (defined('APPLICATION_ENV') && APPLICATION_ENV == "development") {
|
if (defined('APPLICATION_ENV') && APPLICATION_ENV == "development") {
|
||||||
$logger = self::getLogger();
|
$logger = self::getLogger();
|
||||||
$logger->debug(self::toString($p_msg)." - file:".$caller['file'].":".$caller['line']);
|
$logger->debug("[$file : $function() : line $line] - ".self::toString($p_msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue