Adds NullLogger when logging system is missing
parent
0447439f99
commit
fe91a91081
|
@ -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 {}
|
||||
}
|
|
@ -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();
|
||||
}
|
Loading…
Reference in New Issue