ILIAS  release_8 Revision v8.24
class.ilLoggingDBSettings.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
5
13{
14 protected static ?ilLoggingDBSettings $instance = null;
15
16 private bool $enabled = false;
18
19 private int $level;
20 private bool $cache = false;
21 private int $cache_level;
22 private bool $memory_usage = false;
23 private bool $browser = false;
27 private array $browser_users = array();
28
29
30
31 private function __construct()
32 {
33 $this->enabled = (bool) ILIAS_LOG_ENABLED;
34 $this->level = ilLogLevel::INFO;
35 $this->cache_level = ilLogLevel::DEBUG;
36
37 $this->storage = new ilSetting('logging');
38 $this->read();
39 }
40
41 public static function getInstance(): self
42 {
43 if (self::$instance) {
44 return self::$instance;
45 }
46 return self::$instance = new self();
47 }
48
53 public function getLevelByComponent(string $a_component_id): int
54 {
55 $levels = ilLogComponentLevels::getInstance()->getLogComponents();
56 foreach ($levels as $level) {
57 if ($level->getComponentId() == $a_component_id) {
58 if ($level->getLevel()) {
59 return $level->getLevel();
60 }
61 }
62 }
63 return $this->getLevel();
64 }
65
69 protected function getStorage(): ilSetting
70 {
71 return $this->storage;
72 }
73
78 public function isEnabled(): bool
79 {
80 return $this->enabled;
81 }
82
83 public function getLogDir(): string
84 {
85 return ILIAS_LOG_DIR;
86 }
87
88 public function getLogFile(): string
89 {
90 return ILIAS_LOG_FILE;
91 }
92
93 public function getLevel(): int
94 {
95 return $this->level;
96 }
97
98 public function setLevel(int $a_level): void
99 {
100 $this->level = $a_level;
101 }
102
103 public function setCacheLevel(int $a_level): void
104 {
105 $this->cache_level = $a_level;
106 }
107
108 public function getCacheLevel(): int
109 {
110 return $this->cache_level;
111 }
112
113 public function enableCaching(bool $a_status): void
114 {
115 $this->cache = $a_status;
116 }
117
118 public function isCacheEnabled(): bool
119 {
120 return $this->cache;
121 }
122
123 public function enableMemoryUsage(bool $a_stat): void
124 {
125 $this->memory_usage = $a_stat;
126 }
127
128 public function isMemoryUsageEnabled(): bool
129 {
130 return $this->memory_usage;
131 }
132
133 public function isBrowserLogEnabled(): bool
134 {
135 return $this->browser;
136 }
137
138
139 public function isBrowserLogEnabledForUser(string $a_login): bool
140 {
141 if (!$this->isBrowserLogEnabled()) {
142 return false;
143 }
144 if (in_array($a_login, $this->getBrowserLogUsers())) {
145 return true;
146 }
147 return false;
148 }
149
150 public function enableBrowserLog(bool $a_stat): void
151 {
152 $this->browser = $a_stat;
153 }
154
155 public function getBrowserLogUsers(): array
156 {
158 }
159
160 public function setBrowserUsers(array $users): void
161 {
162 $this->browser_users = $users;
163 }
164
165
169 public function update(): void
170 {
171 $this->getStorage()->set('level', (string) $this->getLevel());
172 $this->getStorage()->set('cache', (string) $this->isCacheEnabled());
173 $this->getStorage()->set('cache_level', (string) $this->getCacheLevel());
174 $this->getStorage()->set('memory_usage', (string) $this->isMemoryUsageEnabled());
175 $this->getStorage()->set('browser', (string) $this->isBrowserLogEnabled());
176 $this->getStorage()->set('browser_users', serialize($this->getBrowserLogUsers()));
177 }
178
179
185 private function read(): void
186 {
187 $this->setLevel((int) $this->getStorage()->get('level', (string) $this->level));
188 $this->enableCaching((bool) $this->getStorage()->get('cache', (string) $this->cache));
189 $this->setCacheLevel((int) $this->getStorage()->get('cache_level', (string) $this->cache_level));
190 $this->enableMemoryUsage((bool) $this->getStorage()->get('memory_usage', (string) $this->memory_usage));
191 $this->enableBrowserLog((bool) $this->getStorage()->get('browser', (string) $this->browser));
192 $this->setBrowserUsers((array) unserialize($this->getStorage()->get('browser_users', serialize($this->browser_users))));
193 }
194}
getLevelByComponent(string $a_component_id)
Get level by component.
isBrowserLogEnabledForUser(string $a_login)
isEnabled()
Check if logging is enabled.
static ilLoggingDBSettings $instance
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...