1<?php 2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4include_once './libs/composer/vendor/autoload.php'; 5include_once __DIR__ . '/public/class.ilLogLevel.php'; 6 7 8use Monolog\Logger; 9use Monolog\Processor\MemoryPeakUsageProcessor; 10 11/** 12 * Component logger with individual log levels by component id 13 * 14 * 15 * @author Stefan Meyer 16 * @version $Id$ 17 * 18 */ 19abstract class ilLogger 20{ 21 private $logger = null; 22 23 public function __construct(Logger $logger) 24 { 25 $this->logger = $logger; 26 } 27 28 /** 29 * Check whether current logger is handling a log level 30 * @param int $a_level 31 * @return bool 32 */ 33 public function isHandling($a_level) 34 { 35 return $this->getLogger()->isHandling($a_level); 36 } 37 38 public function log($a_message, $a_level = ilLogLevel::INFO) 39 { 40 return $this->getLogger()->log($a_level, $a_message); 41 } 42 43 public function dump($a_variable, $a_level = ilLogLevel::INFO) 44 { 45 return $this->log(print_r($a_variable, true), $a_level); 46 } 47 48 public function debug($a_message, $a_context = array()) 49 { 50 return $this->getLogger()->debug($a_message, $a_context); 51 } 52 53 public function info($a_message) 54 { 55 return $this->getLogger()->info($a_message); 56 } 57 58 public function notice($a_message) 59 { 60 return $this->getLogger()->notice($a_message); 61 } 62 63 public function warning($a_message) 64 { 65 return $this->getLogger()->warning($a_message); 66 } 67 68 public function error($a_message) 69 { 70 return $this->getLogger()->error($a_message); 71 } 72 73 public function critical($a_message) 74 { 75 $this->getLogger()->critical($a_message); 76 } 77 78 public function alert($a_message) 79 { 80 return $this->getLogger()->alert($a_message); 81 } 82 83 84 public function emergency($a_message) 85 { 86 return $this->getLogger()->emergency($a_message); 87 } 88 89 /** 90 * Get logger instance 91 * @return \Logger 92 */ 93 public function getLogger() 94 { 95 return $this->logger; 96 } 97 98 /** 99 * write log message 100 * @deprecated since version 5.1 101 * @see ilLogger->info(), ilLogger()->debug(), ... 102 */ 103 public function write($a_message, $a_level = ilLogLevel::INFO) 104 { 105 include_once './Services/Logging/classes/public/class.ilLogLevel.php'; 106 if (!in_array($a_level, ilLogLevel::getLevels())) { 107 $a_level = ilLogLevel::INFO; 108 } 109 110 $this->getLogger()->log($a_level, $a_message); 111 } 112 113 /** 114 * Write language log 115 * @deprecated since version 5.1 116 */ 117 public function writeLanguageLog($a_topic, $a_lang_key) 118 { 119 $this->getLogger()->debug("Language (" . $a_lang_key . "): topic -" . $a_topic . "- not present"); 120 } 121 122 /** 123 * log stack trace 124 * @param type $a_level 125 * @param type $a_message 126 * @throws \Exception 127 */ 128 public function logStack($a_level = null, $a_message = '') 129 { 130 if (is_null($a_level)) { 131 $a_level = ilLogLevel::INFO; 132 } 133 134 include_once './Services/Logging/classes/public/class.ilLogLevel.php'; 135 if (!in_array($a_level, ilLogLevel::getLevels())) { 136 $a_level = ilLogLevel::INFO; 137 } 138 139 140 try { 141 throw new \Exception($a_message); 142 } catch (Exception $ex) { 143 $this->getLogger()->log($a_level, $a_message . "\n" . $ex->getTraceAsString()); 144 } 145 } 146 147 /** 148 * Write memory peak usage 149 * Automatically called at end of script 150 * @param int $a_level 151 */ 152 public function writeMemoryPeakUsage($a_level) 153 { 154 $this->getLogger()->pushProcessor(new MemoryPeakUsageProcessor()); 155 $this->getLogger()->log($a_level, 'Memory usage: '); 156 $this->getLogger()->popProcessor(); 157 } 158} 159