2012-03-30 17:15:48 -04:00
|
|
|
<?php
|
2024-05-23 03:26:56 -04:00
|
|
|
|
2012-03-30 17:15:48 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2012-03-30 17:15:48 -04:00
|
|
|
*/
|
2016-05-02 08:04:58 -04:00
|
|
|
namespace OC\Log;
|
|
|
|
|
|
2019-07-16 04:15:00 -04:00
|
|
|
use OC\SystemConfig;
|
2018-04-25 09:22:28 -04:00
|
|
|
use OCP\ILogger;
|
2018-04-24 20:27:43 -04:00
|
|
|
use OCP\Log\IWriter;
|
2018-04-25 09:22:28 -04:00
|
|
|
|
2019-07-16 04:15:00 -04:00
|
|
|
class Syslog extends LogDetails implements IWriter {
|
2023-06-28 01:53:43 -04:00
|
|
|
protected array $levels = [
|
2018-04-25 09:22:28 -04:00
|
|
|
ILogger::DEBUG => LOG_DEBUG,
|
|
|
|
|
ILogger::INFO => LOG_INFO,
|
|
|
|
|
ILogger::WARN => LOG_WARNING,
|
|
|
|
|
ILogger::ERROR => LOG_ERR,
|
|
|
|
|
ILogger::FATAL => LOG_CRIT,
|
2018-04-24 16:14:00 -04:00
|
|
|
];
|
2012-03-30 17:15:48 -04:00
|
|
|
|
2025-07-01 02:01:52 -04:00
|
|
|
private string $tag;
|
|
|
|
|
|
2023-06-28 01:53:43 -04:00
|
|
|
public function __construct(
|
|
|
|
|
SystemConfig $config,
|
|
|
|
|
?string $tag = null,
|
|
|
|
|
) {
|
2019-07-16 04:15:00 -04:00
|
|
|
parent::__construct($config);
|
2022-01-19 10:15:14 -05:00
|
|
|
if ($tag === null) {
|
2025-07-01 02:01:52 -04:00
|
|
|
$this->tag = $config->getValue('syslog_tag', 'Nextcloud');
|
|
|
|
|
} else {
|
|
|
|
|
$this->tag = $tag;
|
2022-01-19 10:15:14 -05:00
|
|
|
}
|
2018-04-25 09:33:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function __destruct() {
|
|
|
|
|
closelog();
|
2012-03-30 17:15:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* write a message in the log
|
2022-12-05 13:54:37 -05:00
|
|
|
* @param string|array $message
|
2012-03-30 17:15:48 -04:00
|
|
|
*/
|
2023-06-28 01:53:43 -04:00
|
|
|
public function write(string $app, $message, int $level): void {
|
2018-04-25 09:33:57 -04:00
|
|
|
$syslog_level = $this->levels[$level];
|
2025-07-01 02:01:52 -04:00
|
|
|
openlog($this->tag, LOG_PID | LOG_CONS, LOG_USER);
|
2019-07-16 04:15:00 -04:00
|
|
|
syslog($syslog_level, $this->logDetailsAsJSON($app, $message, $level));
|
2012-03-30 17:15:48 -04:00
|
|
|
}
|
|
|
|
|
}
|