Skip to content

Commit a290a96

Browse files
committed
(Cron)/Logging: provide logger factory
1 parent 4cd5e61 commit a290a96

4 files changed

Lines changed: 62 additions & 24 deletions

File tree

components/ILIAS/Logging/Logging.php

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,62 @@ public function init(
3232
array | \ArrayAccess &$pull,
3333
array | \ArrayAccess &$internal,
3434
): void {
35+
$define[] = \ILIAS\Logging\LoggerFactory::class;
36+
37+
$implement[\ILIAS\Logging\LoggerFactory::class] = static fn() =>
38+
$internal[\ilLoggerFactory::class];
39+
3540
$contribute[\ILIAS\Setup\Agent::class] = static fn() =>
3641
new \ilLoggingSetupAgent(
3742
$pull[\ILIAS\Refinery\Factory::class]
3843
);
3944
$contribute[\ILIAS\Cron\CronJob::class] = static fn() =>
4045
new \ilLoggerCronCleanErrorFiles(
41-
'components\\' . self::class,
46+
self::class,
4247
$use[\ILIAS\Language\Language::class],
43-
true
48+
$use[\ILIAS\Logging\LoggerFactory::class]
4449
);
50+
$internal[\ilLoggerFactory::class] = static fn() =>
51+
\ilLoggerFactory::getInstance(
52+
$internal[\ilLoggingSettings::class]
53+
);
54+
55+
$internal[\ilLoggingSettings::class] = static fn() =>
56+
new class () implements \ilLoggingSettings {
57+
public function isEnabled(): bool
58+
{
59+
return false;
60+
}
61+
public function getLogDir(): string
62+
{
63+
}
64+
public function getLogFile(): string
65+
{
66+
}
67+
public function getLevel(): int
68+
{
69+
}
70+
public function getLevelByComponent(string $a_component_id): int
71+
{
72+
}
73+
public function getCacheLevel(): int
74+
{
75+
}
76+
public function isCacheEnabled(): bool
77+
{
78+
}
79+
public function isMemoryUsageEnabled(): bool
80+
{
81+
}
82+
public function isBrowserLogEnabled(): bool
83+
{
84+
}
85+
public function isBrowserLogEnabledForUser(string $a_login): bool
86+
{
87+
}
88+
public function getBrowserLogUsers(): array
89+
{
90+
}
91+
};
4592
}
4693
}

components/ILIAS/Logging/classes/error/class.ilLoggerCronCleanErrorFiles.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,10 @@ class ilLoggerCronCleanErrorFiles extends ilCronJob
2727
protected ilSetting $settings;
2828
protected ilLoggingErrorSettings $error_settings;
2929

30-
public function __construct(
31-
string $component,
32-
\ILIAS\Language\Language $lng,
33-
bool $registration = false
34-
) {
35-
parent::__construct($component, $lng);
30+
public function init(): void
31+
{
3632
$this->lng->loadLanguageModule('logging');
37-
if (!$registration) {
38-
$this->additionalConstruct();
39-
}
40-
}
4133

42-
private function additionalConstruct()
43-
{
4434
global $DIC;
4535
$this->settings = new ilSetting('log');
4636
$this->error_settings = ilLoggingErrorSettings::getInstance();

components/ILIAS/Logging/classes/public/class.ilLoggerFactory.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@
2828
use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy;
2929
use ILIAS\DI\Container;
3030
use Monolog\Processor\PsrLogMessageProcessor;
31+
use ILIAS\Logging\LoggerFactory;
3132

3233
/**
3334
* Logging factory
3435
*
3536
* @author Stefan Meyer <smeyer.ilias@gmx.de>
3637
*
3738
*/
38-
class ilLoggerFactory
39+
class ilLoggerFactory implements LoggerFactory
3940
{
4041
protected const DEFAULT_FORMAT = "[%suid%] [%datetime%] %channel%.%level_name%: %message% %context% %extra%\n";
4142

@@ -45,8 +46,7 @@ class ilLoggerFactory
4546

4647
private static ?ilLoggerFactory $instance = null;
4748

48-
private ilLoggingSettings $settings;
49-
protected Container $dic;
49+
protected ?Container $dic;
5050

5151
private bool $enabled = false; //ToDo PHP8 Review: This is a private var never read only written and should probably be removed.
5252

@@ -55,19 +55,21 @@ class ilLoggerFactory
5555
*/
5656
private array $loggers = array();
5757

58-
protected function __construct(ilLoggingSettings $settings)
59-
{
58+
protected function __construct(
59+
private ilLoggingSettings $settings
60+
) {
6061
global $DIC;
61-
6262
$this->dic = $DIC;
63-
$this->settings = $settings;
6463
$this->enabled = $this->getSettings()->isEnabled();
6564
}
6665

67-
public static function getInstance(): ilLoggerFactory
66+
public static function getInstance(?\ilLoggingSettings $settings = null): ilLoggerFactory
6867
{
69-
if (!static::$instance instanceof ilLoggerFactory) {
68+
if (is_null($settings)) {
7069
$settings = ilLoggingDBSettings::getInstance();
70+
static::$instance = null;
71+
}
72+
if (!static::$instance instanceof ilLoggerFactory) {
7173
static::$instance = new ilLoggerFactory($settings);
7274
}
7375
return static::$instance;

components/ILIAS/Logging/src/LoggerFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@
2323

2424
interface LoggerFactory
2525
{
26-
2726
}

0 commit comments

Comments
 (0)