ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilLogger.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use Monolog\Logger;
23 
28 abstract class ilLogger
29 {
30  public function __construct(private readonly Logger $logger)
31  {
32  }
33 
37  public function isHandling(int $level): bool
38  {
39  return $this->getLogger()->isHandling($level);
40  }
41 
42  public function log(string $message, int $level = ilLogLevel::INFO, array $context = []): void
43  {
44  $this->getLogger()->log($level, $message, $context);
45  }
46 
47  public function dump($value, int $level = ilLogLevel::INFO): void
48  {
49  $this->log('{dump}', $level, [
50  'dump' => print_r($value, true),
51  ]);
52  }
53 
54  public function debug(string $message, array $context = []): void
55  {
56  $this->getLogger()->debug($message, $context);
57  }
58 
59  public function info(string $message, array $context = []): void
60  {
61  $this->getLogger()->info($message, $context);
62  }
63 
64  public function notice(string $message, array $context = []): void
65  {
66  $this->getLogger()->notice($message, $context);
67  }
68 
69  public function warning(string $message, array $context = []): void
70  {
71  $this->getLogger()->warning($message, $context);
72  }
73 
74  public function error(string $message, array $context = []): void
75  {
76  $this->getLogger()->error($message, $context);
77  }
78 
79  public function critical(string $message, array $context = []): void
80  {
81  $this->getLogger()->critical($message, $context);
82  }
83 
84  public function alert(string $message, array $context = []): void
85  {
86  $this->getLogger()->alert($message, $context);
87  }
88 
89  public function emergency(string $message, array $context = []): void
90  {
91  $this->getLogger()->emergency($message, $context);
92  }
93 
94  public function getLogger(): Logger
95  {
96  return $this->logger;
97  }
98 
104  public function write(string $message, $level = ilLogLevel::INFO, array $context = []): void
105  {
106  if (!in_array($level, ilLogLevel::getLevels())) {
107  $level = ilLogLevel::INFO;
108  }
109  $this->getLogger()->log((int) $level, $message, $context);
110  }
111 
116  public function writeLanguageLog(string $topic, string $lang_key): void
117  {
118  $this->getLogger()->debug("Language (" . $lang_key . "): topic -" . $topic . "- not present");
119  }
120 
121  public function logStack(?int $level = null, string $message = '', array $context = []): void
122  {
123  if (is_null($level)) {
124  $level = ilLogLevel::INFO;
125  }
126 
127  if (!in_array($level, ilLogLevel::getLevels())) {
128  $level = ilLogLevel::INFO;
129  }
130 
131 
132  try {
133  throw new Exception($message);
134  } catch (Exception $ex) {
135  $this->getLogger()->log($level, $message . "\n" . $ex->getTraceAsString(), $context);
136  }
137  }
138 
143  public function writeMemoryPeakUsage(int $level): void
144  {
145  $this->getLogger()->pushProcessor(new MemoryPeakUsageProcessor());
146  $this->getLogger()->log($level, 'Memory usage: ');
147  $this->getLogger()->popProcessor();
148  }
149 }
notice(string $message, array $context=[])
$context
Definition: webdav.php:31
dump($value, int $level=ilLogLevel::INFO)
logStack(?int $level=null, string $message='', array $context=[])
write(string $message, $level=ilLogLevel::INFO, array $context=[])
write log message
emergency(string $message, array $context=[])
log(string $message, int $level=ilLogLevel::INFO, array $context=[])
static getLevels()
warning(string $message, array $context=[])
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
writeLanguageLog(string $topic, string $lang_key)
Write language log.
__construct(private readonly Logger $logger)
info(string $message, array $context=[])
writeMemoryPeakUsage(int $level)
Write memory peak usage Automatically called at end of script.
alert(string $message, array $context=[])
critical(string $message, array $context=[])
$message
Definition: xapiexit.php:31
isHandling(int $level)
Check whether current logger is handling a log level.
debug(string $message, array $context=[])
error(string $message, array $context=[])