context.php: initial add LogDriver

This commit is contained in:
Zankaria 2024-12-19 00:23:39 +01:00
parent 707fb62c04
commit 79523f8251

View file

@ -3,6 +3,7 @@ namespace Vichan;
use Vichan\Data\Driver\CacheDriver;
use Vichan\Data\{IpNoteQueries, ReportQueries, UserPostQueries};
use Vichan\Data\Driver\{LogDriver, LogDrivers};
defined('TINYBOARD') or exit;
@ -31,6 +32,26 @@ class Context {
function build_context(array $config): Context {
return new Context([
'config' => $config,
LogDriver::class => function($c) {
$config = $c->get('config');
$name = $config['log_system']['name'];
$level = $config['debug'] ? LogDriver::DEBUG : LogDriver::NOTICE;
$backend = $config['log_system']['type'];
// Check 'syslog' for backwards compatibility.
if ((isset($config['syslog']) && $config['syslog']) || $backend === 'syslog') {
return LogDrivers::syslog($name, $level, $this->config['log_system']['syslog_stderr']);
} elseif ($backend === 'file') {
return LogDrivers::file($name, $level, $this->config['log_system']['file_path']);
} elseif ($backend === 'stderr') {
return LogDrivers::stderr($name, $level);
} elseif ($backend === 'none') {
return LogDrivers::none();
} else {
return LogDrivers::error_log($name, $level);
}
},
CacheDriver::class => function($c) {
// Use the global for backwards compatibility.
return \cache::getCache();