ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLogger.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use Monolog\Logger;
22use Monolog\Processor\MemoryPeakUsageProcessor;
23
28abstract 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}
static getLevels()
Component logger with individual log levels by component id.
log(string $message, int $level=ilLogLevel::INFO, array $context=[])
emergency(string $message, array $context=[])
info(string $message, array $context=[])
critical(string $message, array $context=[])
notice(string $message, array $context=[])
writeLanguageLog(string $topic, string $lang_key)
Write language log.
isHandling(int $level)
Check whether current logger is handling a log level.
writeMemoryPeakUsage(int $level)
Write memory peak usage Automatically called at end of script.
alert(string $message, array $context=[])
write(string $message, $level=ilLogLevel::INFO, array $context=[])
write log message
dump($value, int $level=ilLogLevel::INFO)
debug(string $message, array $context=[])
warning(string $message, array $context=[])
__construct(private readonly Logger $logger)
error(string $message, array $context=[])
logStack(?int $level=null, string $message='', array $context=[])
$context
Definition: webdav.php:31
$message
Definition: xapiexit.php:31