fix(syslog): open syslog channel on write

This fixes a bug where only one tag gets used when multiple tags have
been configured (e.g. different tags for 'syslog_tag' and 'syslog_tag_audit')

Signed-off-by: Kent Delante <kent.delante@proton.me>
pull/53738/head
Kent Delante 2025-07-01 14:01:52 +07:00
parent 44a9fa262a
commit eb58d2bb5a
1 changed files with 6 additions and 2 deletions

@ -20,15 +20,18 @@ class Syslog extends LogDetails implements IWriter {
ILogger::FATAL => LOG_CRIT,
];
private string $tag;
public function __construct(
SystemConfig $config,
?string $tag = null,
) {
parent::__construct($config);
if ($tag === null) {
$tag = $config->getValue('syslog_tag', 'Nextcloud');
$this->tag = $config->getValue('syslog_tag', 'Nextcloud');
} else {
$this->tag = $tag;
}
openlog($tag, LOG_PID | LOG_CONS, LOG_USER);
}
public function __destruct() {
@ -41,6 +44,7 @@ class Syslog extends LogDetails implements IWriter {
*/
public function write(string $app, $message, int $level): void {
$syslog_level = $this->levels[$level];
openlog($this->tag, LOG_PID | LOG_CONS, LOG_USER);
syslog($syslog_level, $this->logDetailsAsJSON($app, $message, $level));
}
}