4 * Simple Logging Manager.
5 * This does an error_log for now
6 * Potential frameworks to use are PEAR logger, log4php from Apache
20 // ERROR Logging Level
24 class PPLoggingManager {
26 // Default Logging Level
27 const DEFAULT_LOGGING_LEVEL = 0;
33 private $isLoggingEnabled;
35 // Configured logging level
36 private $loggingLevel;
38 // Configured logging file
41 public function __construct($loggerName, $config = null) {
42 $this->loggerName = $loggerName;
44 $config = PPConfigManager::getInstance()->getConfigHashmap();
46 $this->isLoggingEnabled = (array_key_exists('log.LogEnabled', $config) && $config['log.LogEnabled'] == '1');
48 if($this->isLoggingEnabled) {
49 $this->loggerFile = ($config['log.FileName']) ? $config['log.FileName'] : ini_get('error_log');
50 $loggingLevel = strtoupper($config['log.LogLevel']);
51 $this->loggingLevel = (isset($loggingLevel) && defined(__NAMESPACE__."\\PPLoggingLevel::$loggingLevel")) ? constant(__NAMESPACE__."\\PPLoggingLevel::$loggingLevel") : PPLoggingManager::DEFAULT_LOGGING_LEVEL;
55 private function log($message, $level=PPLoggingLevel::INFO) {
56 if($this->isLoggingEnabled && ($level <= $this->loggingLevel)) {
57 error_log( $this->loggerName . ": $message\n", 3, $this->loggerFile);
61 public function error($message) {
62 $this->log($message, PPLoggingLevel::ERROR);
65 public function warning($message) {
66 $this->log($message, PPLoggingLevel::WARN);
69 public function info($message) {
70 $this->log($message, PPLoggingLevel::INFO);
73 public function fine($message) {
74 $this->log($message, PPLoggingLevel::FINE);