nulib/php/src_output/log.php

31 lines
755 B
PHP
Raw Normal View History

2023-12-28 17:32:27 +04:00
<?php
namespace nulib\output;
use nulib\ValueException;
use nulib\output\std\ProxyMessenger;
/**
* Class log: inscrire un message dans les logs uniquement
*/
class log extends _messenger {
static function set_messenger(IMessenger $log=null) {
self::$log = $log;
}
static function set_messenger_class(string $log_class=null, ?array $params=null) {
if (!is_subclass_of($log_class, IMessenger::class)) {
throw ValueException::invalid_class($log_class, IMessenger::class);
}
self::$log = new $log_class($params);
}
static function get(): IMessenger {
if (self::$msg === null) {
$msg = self::$log;
if ($msg === null) $msg = new ProxyMessenger();
self::$msg = $msg;
}
return self::$msg;
}
}