jilo-web/app/classes/log.php

43 lines
1.1 KiB
PHP
Raw Normal View History

2024-09-16 14:09:37 +00:00
<?php
2024-11-22 13:33:19 +00:00
/**
* Log wrapper that delegates to plugin Log or NullLogger fallback.
* Used when code does require_once '../app/classes/log.php'.
2024-11-22 13:33:19 +00:00
*/
// If there is already a Log plugin loaded
if (class_exists('Log')) {
return;
}
// Load fallback NullLogger
require_once __DIR__ . '/../core/NullLogger.php';
2024-09-16 14:09:37 +00:00
class Log {
private $logger;
2024-09-16 14:09:37 +00:00
2024-11-22 13:33:19 +00:00
/**
* @param mixed $database Database or DatabaseConnector instance
2024-11-22 13:33:19 +00:00
*/
2024-09-16 14:09:37 +00:00
public function __construct($database) {
global $logObject;
if (isset($logObject) && method_exists($logObject, 'insertLog')) {
$this->logger = $logObject;
2025-04-14 15:07:15 +00:00
} else {
$this->logger = new \App\Core\NullLogger();
2024-09-16 14:09:37 +00:00
}
}
2024-11-22 13:33:19 +00:00
/**
* Delegate insertLog to underlying logger
2024-11-22 13:33:19 +00:00
*
* @param mixed $userId
* @param string $message
* @param string|null $scope
* @return mixed True on success or error message
2024-11-22 13:33:19 +00:00
*/
public function insertLog($userId, string $message, ?string $scope = null) {
return $this->logger->insertLog($userId, $message, $scope);
2024-09-16 14:09:37 +00:00
}
}