ILIAS  release_8 Revision v8.24
class.ilLogger.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
6
7include_once __DIR__ . '/../../../libs/composer/vendor/autoload.php';
8
9use Monolog\Logger;
10use Monolog\Processor\MemoryPeakUsageProcessor;
11
16abstract class ilLogger
17{
18 private Logger $logger;
19
20 public function __construct(Logger $logger)
21 {
22 $this->logger = $logger;
23 }
24
28 public function isHandling(int $a_level): bool
29 {
30 return $this->getLogger()->isHandling($a_level);
31 }
32
33 public function log(string $a_message, int $a_level = ilLogLevel::INFO): void
34 {
35 $this->getLogger()->log($a_level, $a_message);
36 }
37
43 public function dump($a_variable, int $a_level = ilLogLevel::INFO): void
44 {
45 $this->log((string) print_r($a_variable, true), $a_level);
46 }
47
48 public function debug(string $a_message, array $a_context = array()): void
49 {
50 $this->getLogger()->debug($a_message, $a_context);
51 }
52
53 public function info(string $a_message): void
54 {
55 $this->getLogger()->info($a_message);
56 }
57
58 public function notice(string $a_message): void
59 {
60 $this->getLogger()->notice($a_message);
61 }
62
63 public function warning(string $a_message): void
64 {
65 $this->getLogger()->warning($a_message);
66 }
67
68 public function error(string $a_message): void
69 {
70 $this->getLogger()->error($a_message);
71 }
72
73 public function critical(string $a_message): void
74 {
75 $this->getLogger()->critical($a_message);
76 }
77
78 public function alert(string $a_message): void
79 {
80 $this->getLogger()->alert($a_message);
81 }
82
83
84 public function emergency(string $a_message): void
85 {
86 $this->getLogger()->emergency($a_message);
87 }
88
89 public function getLogger(): Logger
90 {
91 return $this->logger;
92 }
93
101 public function write(string $a_message, $a_level = ilLogLevel::INFO): void
102 {
103 if (!in_array($a_level, ilLogLevel::getLevels())) {
104 $a_level = ilLogLevel::INFO;
105 }
106 $this->getLogger()->log((int) $a_level, $a_message);
107 }
108
113 public function writeLanguageLog(string $a_topic, string $a_lang_key): void
114 {
115 $this->getLogger()->debug("Language (" . $a_lang_key . "): topic -" . $a_topic . "- not present");
116 }
117
118 public function logStack(?int $a_level = null, string $a_message = ''): void
119 {
120 if (is_null($a_level)) {
121 $a_level = ilLogLevel::INFO;
122 }
123
124 if (!in_array($a_level, ilLogLevel::getLevels())) {
125 $a_level = ilLogLevel::INFO;
126 }
127
128
129 try {
130 throw new \Exception($a_message);
131 } catch (Exception $ex) {
132 $this->getLogger()->log($a_level, $a_message . "\n" . $ex->getTraceAsString());
133 }
134 }
135
140 public function writeMemoryPeakUsage(int $a_level): void
141 {
142 $this->getLogger()->pushProcessor(new MemoryPeakUsageProcessor());
143 $this->getLogger()->log($a_level, 'Memory usage: ');
144 $this->getLogger()->popProcessor();
145 }
146}
static getLevels()
Component logger with individual log levels by component id.
Logger $logger
writeMemoryPeakUsage(int $a_level)
Write memory peak usage Automatically called at end of script.
__construct(Logger $logger)
notice(string $a_message)
info(string $a_message)
alert(string $a_message)
warning(string $a_message)
isHandling(int $a_level)
Check whether current logger is handling a log level.
dump($a_variable, int $a_level=ilLogLevel::INFO)
write(string $a_message, $a_level=ilLogLevel::INFO)
write log message
emergency(string $a_message)
debug(string $a_message, array $a_context=array())
error(string $a_message)
writeLanguageLog(string $a_topic, string $a_lang_key)
Write language log.
log(string $a_message, int $a_level=ilLogLevel::INFO)
critical(string $a_message)
logStack(?int $a_level=null, string $a_message='')