19 declare(strict_types=1);
39 protected const DEFAULT_FORMAT =
"[%suid%] [%datetime%] %channel%.%level_name%: %message% %context% %extra%\n";
70 static::$instance =
new ilLoggerFactory($settings);
72 return static::$instance;
77 return static::$instance =
new self(
$settings);
91 $factory = self::getInstance();
92 return $factory->getComponentLogger($a_component_id);
100 $factory = self::getInstance();
101 return $factory->getComponentLogger(self::ROOT_LOGGER);
110 if (!$this->
getSettings()->isBrowserLogEnabledForUser($a_login)) {
114 foreach ($this->loggers as $a_component_id => $logger) {
116 $browser_handler =
new BrowserConsoleHandler();
117 $browser_handler->setLevel($this->
getSettings()->getLevelByComponent($a_component_id));
118 $browser_handler->setFormatter(
new ilLineFormatter(static::DEFAULT_FORMAT,
'Y-m-d H:i:s.u',
true,
true));
119 $logger->getLogger()->pushHandler($browser_handler);
133 $this->dic->isDependencyAvailable(
'ctrl') && $this->dic->ctrl()->isAsynch() ||
135 $this->dic->isDependencyAvailable(
'http') &&
136 strtolower($this->dic->http()->request()->getServerParams()[
'HTTP_X_REQUESTED_WITH'] ??
'') ===
'xmlhttprequest' 143 $this->dic->isDependencyAvailable(
'http') &&
144 strpos($this->dic->http()->request()->getServerParams()[
'HTTP_ACCEPT'],
'text/html') !==
false 149 $this->dic->isDependencyAvailable(
'http') &&
150 strpos($this->dic->http()->request()->getServerParams()[
'HTTP_ACCEPT'],
'application/json') !==
false 172 if (isset($this->loggers[$a_component_id])) {
173 return $this->loggers[$a_component_id];
176 $loggerNamePrefix =
'';
177 if (defined(
'CLIENT_ID')) {
181 switch ($a_component_id) {
183 $logger =
new Logger($loggerNamePrefix .
'root');
187 $logger =
new Logger($loggerNamePrefix . $a_component_id);
192 $null_handler =
new NullHandler();
193 $logger->pushHandler($null_handler);
200 $stream_handler =
new StreamHandler(
206 if ($a_component_id == self::ROOT_LOGGER) {
207 $stream_handler->setLevel($this->
getSettings()->getLevelByComponent(self::COMPONENT_ROOT));
209 $stream_handler->setLevel($this->
getSettings()->getLevelByComponent($a_component_id));
213 $line_formatter =
new ilLineFormatter(static::DEFAULT_FORMAT,
'Y-m-d H:i:s.u',
true,
true);
214 $stream_handler->setFormatter($line_formatter);
218 $finger_crossed_handler =
new FingersCrossedHandler(
220 new ErrorLevelActivationStrategy($this->
getSettings()->getCacheLevel()),
223 $logger->pushHandler($finger_crossed_handler);
225 $logger->pushHandler($stream_handler);
229 $this->dic->offsetExists(
'ilUser') &&
232 if ($this->
getSettings()->isBrowserLogEnabledForUser($this->dic->user()->getLogin())) {
234 $browser_handler =
new BrowserConsoleHandler();
235 $browser_handler->setLevel($this->
getSettings()->getLevel());
236 $browser_handler->setFormatter($line_formatter);
237 $logger->pushHandler($browser_handler);
244 $logger->pushProcessor(
function ($record) {
245 $record[
'suid'] = substr(session_id(), 0, 5);
253 $logger->pushProcessor(
new PsrLogMessageProcessor());
258 return $this->loggers[$a_component_id];
static getLogger(string $a_component_id)
Get component logger.
static newInstance(ilLoggingSettings $settings)
Component logger with individual log levels by component id.
Customizing of pimple-DIC for ILIAS.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
ilLoggingSettings $settings
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isConsoleAvailable()
Check if console handler is available.
static ilLoggerFactory $instance
getComponentLogger(string $a_component_id)
__construct(ilLoggingSettings $settings)
static getType()
Get context type.
initUser(string $a_login)
Init user specific log options.
static getRootLogger()
The unique root logger has a fixed error level.