jilo-web/app/classes/log.php

41 lines
993 B
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
/**
2025-04-27 16:21:23 +00:00
* PSR-3 compatible log method
* @param string $level
* @param string $message
2025-04-27 16:21:23 +00:00
* @param array $context
2024-11-22 13:33:19 +00:00
*/
2025-04-27 16:21:23 +00:00
public function log(string $level, string $message, array $context = []): void {
$this->logger->log($level, $message, $context);
2024-09-16 14:09:37 +00:00
}
}