Files
fdn2/app/private/lib/logger/LoggingFacility.php
T
2022-08-29 23:20:16 +02: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("%d/%m/%Y %H:%M:%S",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;
}
}
?>