context.php: update LogDriver

This commit is contained in:
Zankaria 2024-10-04 12:57:37 +02:00
parent 36d48951c1
commit 79af4b34dd

View File

@ -2,8 +2,7 @@
namespace Vichan; namespace Vichan;
use RuntimeException; use RuntimeException;
use Vichan\Driver\{Log, LogDrivers}; use Vichan\Data\Driver\{HttpDriver, ErrorLogLogDriver, FileLogDriver, LogDriver, StderrLogDriver, SyslogLogDriver};
use Vichan\Data\Driver\HttpDriver;
use Vichan\Service\HCaptchaQuery; use Vichan\Service\HCaptchaQuery;
use Vichan\Service\NativeCaptchaQuery; use Vichan\Service\NativeCaptchaQuery;
use Vichan\Service\ReCaptchaQuery; use Vichan\Service\ReCaptchaQuery;
@ -35,24 +34,22 @@ class Context {
function build_context(array $config): Context { function build_context(array $config): Context {
return new Context([ return new Context([
'config' => $config, 'config' => $config,
Log::class => function($c) { LogDriver::class => function($c) {
$config = $c->get('config'); $config = $c->get('config');
$name = $config['log_system']['name']; $name = $config['log_system']['name'];
$level = $config['debug'] ? Log::DEBUG : Log::NOTICE; $level = $config['debug'] ? LogDriver::DEBUG : LogDriver::NOTICE;
$backend = $config['log_system']['type']; $backend = $config['log_system']['type'];
// Check 'syslog' for backwards compatibility. // Check 'syslog' for backwards compatibility.
if ((isset($config['syslog']) && $config['syslog']) || $backend === 'syslog') { if ((isset($config['syslog']) && $config['syslog']) || $backend === 'syslog') {
return LogDrivers::syslog($name, $level, $this->config['log_system']['syslog_stderr']); return new SyslogLogDriver($name, $level, $this->config['log_system']['syslog_stderr']);
} elseif ($backend === 'file') { } elseif ($backend === 'file') {
return LogDrivers::file($name, $level, $this->config['log_system']['file_path']); return new FileLogDriver($name, $level, $this->config['log_system']['file_path']);
} elseif ($backend === 'stderr') { } elseif ($backend === 'stderr') {
return LogDrivers::stderr($name, $level); return new StderrLogDriver($name, $level);
} elseif ($backend === 'none') {
return LogDrivers::none();
} else { } else {
return LogDrivers::error_log($name, $level); return new ErrorLogLogDriver($name, $level);
} }
}, },
HttpDriver::class => function($c) { HttpDriver::class => function($c) {