ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLoggingDBSettings.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
27{
28 protected static ?ilLoggingDBSettings $instance = null;
29
30 private bool $enabled = false;
32
33 private int $level;
34 private bool $cache = false;
35 private int $cache_level;
36 private bool $memory_usage = false;
37 private bool $browser = false;
41 private array $browser_users = array();
42
43
44
45 private function __construct()
46 {
47 $this->enabled = (bool) ILIAS_LOG_ENABLED;
48 $this->level = ilLogLevel::INFO;
49 $this->cache_level = ilLogLevel::DEBUG;
50
51 $this->storage = new ilSetting('logging');
52 $this->read();
53 }
54
55 public static function getInstance(): self
56 {
57 if (self::$instance) {
58 return self::$instance;
59 }
60 return self::$instance = new self();
61 }
62
67 public function getLevelByComponent(string $a_component_id): int
68 {
69 $levels = ilLogComponentLevels::getInstance()->getLogComponents();
70 foreach ($levels as $level) {
71 if ($level->getComponentId() == $a_component_id) {
72 if ($level->getLevel()) {
73 return $level->getLevel();
74 }
75 }
76 }
77 return $this->getLevel();
78 }
79
83 protected function getStorage(): ilSetting
84 {
85 return $this->storage;
86 }
87
92 public function isEnabled(): bool
93 {
94 return $this->enabled;
95 }
96
97 public function getLogDir(): string
98 {
99 return ILIAS_LOG_DIR;
100 }
101
102 public function getLogFile(): string
103 {
104 return ILIAS_LOG_FILE;
105 }
106
107 public function getLevel(): int
108 {
109 return $this->level;
110 }
111
112 public function setLevel(int $a_level): void
113 {
114 $this->level = $a_level;
115 }
116
117 public function setCacheLevel(int $a_level): void
118 {
119 $this->cache_level = $a_level;
120 }
121
122 public function getCacheLevel(): int
123 {
124 return $this->cache_level;
125 }
126
127 public function enableCaching(bool $a_status): void
128 {
129 $this->cache = $a_status;
130 }
131
132 public function isCacheEnabled(): bool
133 {
134 return $this->cache;
135 }
136
137 public function enableMemoryUsage(bool $a_stat): void
138 {
139 $this->memory_usage = $a_stat;
140 }
141
142 public function isMemoryUsageEnabled(): bool
143 {
144 return $this->memory_usage;
145 }
146
147 public function isBrowserLogEnabled(): bool
148 {
149 return $this->browser;
150 }
151
152
153 public function isBrowserLogEnabledForUser(string $a_login): bool
154 {
155 if (!$this->isBrowserLogEnabled()) {
156 return false;
157 }
158 if (in_array($a_login, $this->getBrowserLogUsers())) {
159 return true;
160 }
161 return false;
162 }
163
164 public function enableBrowserLog(bool $a_stat): void
165 {
166 $this->browser = $a_stat;
167 }
168
169 public function getBrowserLogUsers(): array
170 {
172 }
173
174 public function setBrowserUsers(array $users): void
175 {
176 $this->browser_users = $users;
177 }
178
179
183 public function update(): void
184 {
185 $this->getStorage()->set('level', (string) $this->getLevel());
186 $this->getStorage()->set('cache', (string) $this->isCacheEnabled());
187 $this->getStorage()->set('cache_level', (string) $this->getCacheLevel());
188 $this->getStorage()->set('memory_usage', (string) $this->isMemoryUsageEnabled());
189 $this->getStorage()->set('browser', (string) $this->isBrowserLogEnabled());
190 $this->getStorage()->set('browser_users', serialize($this->getBrowserLogUsers()));
191 }
192
193
199 private function read(): void
200 {
201 $this->setLevel((int) $this->getStorage()->get('level', (string) $this->level));
202 $this->enableCaching((bool) $this->getStorage()->get('cache', (string) $this->cache));
203 $this->setCacheLevel((int) $this->getStorage()->get('cache_level', (string) $this->cache_level));
204 $this->enableMemoryUsage((bool) $this->getStorage()->get('memory_usage', (string) $this->memory_usage));
205 $this->enableBrowserLog((bool) $this->getStorage()->get('browser', (string) $this->browser));
206 $this->setBrowserUsers((array) unserialize($this->getStorage()->get('browser_users', serialize($this->browser_users))));
207 }
208}
getLevelByComponent(string $a_component_id)
Get level by component.
isBrowserLogEnabledForUser(string $a_login)
isEnabled()
Check if logging is enabled.
static ilLoggingDBSettings $instance
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...