Skip to content

Commit

Permalink
(Cron)/Logging: provide logger factory
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaagen committed Jan 2, 2025
1 parent 4d29dce commit b831d46
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 24 deletions.
51 changes: 49 additions & 2 deletions components/ILIAS/Logging/Logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,62 @@ public function init(
array | \ArrayAccess &$pull,
array | \ArrayAccess &$internal,
): void {
$define[] = \ILIAS\Logging\LoggerFactory::class;

$implement[\ILIAS\Logging\LoggerFactory::class] = static fn() =>
$internal[\ilLoggerFactory::class];

$contribute[\ILIAS\Setup\Agent::class] = static fn() =>
new \ilLoggingSetupAgent(
$pull[\ILIAS\Refinery\Factory::class]
);
$contribute[\ILIAS\Cron\CronJob::class] = static fn() =>
new \ilLoggerCronCleanErrorFiles(
'components\\' . self::class,
self::class,
$use[\ILIAS\Language\Language::class],
true
$use[\ILIAS\Logging\LoggerFactory::class]
);
$internal[\ilLoggerFactory::class] = static fn() =>
\ilLoggerFactory::getInstance(
$internal[\ilLoggingSettings::class]
);

$internal[\ilLoggingSettings::class] = static fn() =>
new class () implements \ilLoggingSettings {
public function isEnabled(): bool
{
return false;
}
public function getLogDir(): string
{
}
public function getLogFile(): string
{
}
public function getLevel(): int
{
}
public function getLevelByComponent(string $a_component_id): int
{
}
public function getCacheLevel(): int
{
}
public function isCacheEnabled(): bool
{
}
public function isMemoryUsageEnabled(): bool
{
}
public function isBrowserLogEnabled(): bool
{
}
public function isBrowserLogEnabledForUser(string $a_login): bool
{
}
public function getBrowserLogUsers(): array
{
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,10 @@ class ilLoggerCronCleanErrorFiles extends ilCronJob
protected ilSetting $settings;
protected ilLoggingErrorSettings $error_settings;

public function __construct(
string $component,
\ILIAS\Language\Language $lng,
bool $registration = false
) {
parent::__construct($component, $lng);
public function init(): void
{
$this->lng->loadLanguageModule('logging');
if (!$registration) {
$this->additionalConstruct();
}
}

private function additionalConstruct()
{
global $DIC;
$this->settings = new ilSetting('log');
$this->error_settings = ilLoggingErrorSettings::getInstance();
Expand Down
20 changes: 11 additions & 9 deletions components/ILIAS/Logging/classes/public/class.ilLoggerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy;
use ILIAS\DI\Container;
use Monolog\Processor\PsrLogMessageProcessor;
use ILIAS\Logging\LoggerFactory;

/**
* Logging factory
*
* @author Stefan Meyer <[email protected]>
*
*/
class ilLoggerFactory
class ilLoggerFactory implements LoggerFactory
{
protected const DEFAULT_FORMAT = "[%suid%] [%datetime%] %channel%.%level_name%: %message% %context% %extra%\n";

Expand All @@ -45,8 +46,7 @@ class ilLoggerFactory

private static ?ilLoggerFactory $instance = null;

private ilLoggingSettings $settings;
protected Container $dic;
protected ?Container $dic;

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

Expand All @@ -55,19 +55,21 @@ class ilLoggerFactory
*/
private array $loggers = array();

protected function __construct(ilLoggingSettings $settings)
{
protected function __construct(
private ilLoggingSettings $settings
) {
global $DIC;

$this->dic = $DIC;
$this->settings = $settings;
$this->enabled = $this->getSettings()->isEnabled();
}

public static function getInstance(): ilLoggerFactory
public static function getInstance(?\ilLoggingSettings $settings = null): ilLoggerFactory
{
if (!static::$instance instanceof ilLoggerFactory) {
if (is_null($settings)) {
$settings = ilLoggingDBSettings::getInstance();
static::$instance = null;
}
if (!static::$instance instanceof ilLoggerFactory) {
static::$instance = new ilLoggerFactory($settings);
}
return static::$instance;
Expand Down
1 change: 0 additions & 1 deletion components/ILIAS/Logging/src/LoggerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@

interface LoggerFactory
{

}

0 comments on commit b831d46

Please sign in to comment.