Adds NullLogger when logging system is missing

main
Yasen Pramatarov 2025-04-25 09:52:48 +03:00
parent 0447439f99
commit fe91a91081
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,19 @@
<?php
namespace App\Core;
/**
* NullLogger is a fallback for disabling logging when there is no logging plugin enabled.
*/
class NullLogger
{
/**
* No-op insertLog.
*
* @param mixed $userId
* @param string $message
* @param string|null $type
* @return void
*/
public function insertLog($userId, string $message, ?string $type = null): void {}
}

View File

@ -0,0 +1,15 @@
<?php
/**
* Returns a logger instance: plugin Log if available, otherwise NullLogger.
*
* @param mixed $database Database or DatabaseConnector instance.
* @return mixed Logger instance with insertLog() method.
*/
function getLoggerInstance($database) {
if (class_exists('Log')) {
return new Log($database);
}
require_once __DIR__ . '/../core/NullLogger.php';
return new \App\Core\NullLogger();
}