From 55cb6bc400513ea5ca23ea0aac6cefa7c212f122 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 3 Apr 2024 23:42:05 +0200 Subject: [PATCH] context.php: add log driver --- inc/context.php | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/inc/context.php b/inc/context.php index 5e540bab..3e52b569 100644 --- a/inc/context.php +++ b/inc/context.php @@ -1,24 +1,53 @@ config['log_system']['name']; + $level = $this->config['debug'] ? Log::DEBUG : Log::NOTICE; + $backend = $this->config['log_system']['type']; + + // Check 'syslog' for backwards compatibility. + if ((isset($this->config['syslog']) && $this->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); + } + } + + public function __construct(array $config) { $this->config = $config; } + public function getLog(): Log { + if (is_null($this->log)) { + $this->log = $this->initLogDriver(); + } + return $this->log; + } + public function getHttpDriver(): HttpDriver { if (is_null($this->http)) { $this->http = HttpDrivers::getHttpDriver($this->config['upload_by_url_timeout'], $this->config['max_filesize']);