Files
fdn2/private/lib/logger/LoggingFacility.php
T
Riccardo Di Dato 4ddbe4ffc2 Creato sistema di deploy (INPROGRESS)
Importate librerie fondamentali:
Logger (UNTESTED)
System (UNTESTED)
Dao (INCOMPLETE)
2015-12-22 22:08:30 +01:00

61 lines
1.6 KiB
PHP

<?php
/*
Author: Riccardo Di Dato
Creation Date: 04/feb/2013
*/
abstract class LoggingFacility {
public static $LEVEL_ERROR = 1;
public static $LEVEL_WARNING = 2;
public static $LEVEL_INFO = 3;
public static $LEVEL_DEBUG = 4;
private $myname;
private $useDate;
private $mylevel;
private $catalogManager;
public function __construct($name,$catalogMan,$prependDate=false) {
$this->myname = $name;
$this->useDate = $prependDate;
$this->mylevel = self::$LEVEL_ERROR;
$this->catalogManager = $catalogMan;
}
public function setLoggingLevel($level) {
if ($level < self::$LEVEL_ERROR) $this->mylevel = self::$LEVEL_ERROR;
else if ($level > self::$LEVEL_DEBUG) $this->mylevel = self::$LEVEL_DEBUG;
else $this->mylevel = $level;
}
public function log($level, $message, $data = null,$usecatalog = false) {
if($level <= $this->mylevel) {
if(!is_array($data)) $data = array($data);
if($usecatalog) $finalMessage = $this->catalogManager->getCatalog($message,$data);
else $finalMessage = $message;
if($this->useDate) {
$formattedDate = strftime($this->catalogManager->getCatalog("core.dateformat"),time());
$finalMessage = $this->myname . " " . $this->getIndicationForLevel($level)
. " - " . $formattedDate . " > " . $finalMessage;
}
else {
$finalMessage = $this->myname . " " . $this->getIndicationForLevel($level)
. " > " . $finalMessage;
}
$this->writelog($level,$finalMessage,$data);
}
}
protected abstract function writelog($level,$message,&$data);
protected abstract function getIndicationForLevel($level);
public function getName() {
return $this->myname;
}
}
?>