Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-01-19 18:15:14 +0300
committerVincent Petry (Rebase PR Action) <PVince81@users.noreply.github.com>2022-02-16 19:02:09 +0300
commit67a8d3f736cb500c2a285d4e9627030bd4e1a1e7 (patch)
tree023e8bbfc1b1d67ff3ac603d1701782557c824bf /lib/private
parentf08ac1efcffb8b238bd0753359df7037dfba7da0 (diff)
Allow to get custom loggers for syslog, errorlog and systemdlog too
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Log/Errorlog.php9
-rw-r--r--lib/private/Log/LogFactory.php20
-rw-r--r--lib/private/Log/Syslog.php7
-rw-r--r--lib/private/Log/Systemdlog.php7
4 files changed, 36 insertions, 7 deletions
diff --git a/lib/private/Log/Errorlog.php b/lib/private/Log/Errorlog.php
index ebcb73be4ce..d27759d7050 100644
--- a/lib/private/Log/Errorlog.php
+++ b/lib/private/Log/Errorlog.php
@@ -29,6 +29,13 @@ use OCP\Log\IWriter;
class Errorlog implements IWriter {
+ /** @var string */
+ protected $tag;
+
+ public function __construct(string $tag = 'owncloud') {
+ $this->tag = $tag;
+ }
+
/**
* write a message in the log
* @param string $app
@@ -36,6 +43,6 @@ class Errorlog implements IWriter {
* @param int $level
*/
public function write(string $app, $message, int $level) {
- error_log('[owncloud]['.$app.']['.$level.'] '.$message);
+ error_log('[' . $this->tag . ']['.$app.']['.$level.'] '.$message);
}
}
diff --git a/lib/private/Log/LogFactory.php b/lib/private/Log/LogFactory.php
index f0f804cd51c..807ff501e39 100644
--- a/lib/private/Log/LogFactory.php
+++ b/lib/private/Log/LogFactory.php
@@ -70,8 +70,24 @@ class LogFactory implements ILogFactory {
return new Log($log, $this->systemConfig);
}
- public function getCustomPsrLogger(string $path): LoggerInterface {
- $log = $this->buildLogFile($path);
+ protected function createNewLogger(string $type, string $tag, string $path): IWriter {
+ switch (strtolower($type)) {
+ case 'errorlog':
+ return new Errorlog($tag);
+ case 'syslog':
+ return new Syslog($this->systemConfig, $tag);
+ case 'systemd':
+ return new Systemdlog($this->systemConfig, $tag);
+ case 'file':
+ case 'owncloud':
+ case 'nextcloud':
+ default:
+ return $this->buildLogFile($path);
+ }
+ }
+
+ public function getCustomPsrLogger(string $path, string $type = 'file', string $tag = 'Nextcloud'): LoggerInterface {
+ $log = $this->createNewLogger($type, $tag, $path);
return new PsrLoggerAdapter(
new Log($log, $this->systemConfig)
);
diff --git a/lib/private/Log/Syslog.php b/lib/private/Log/Syslog.php
index 7c3d1a54b78..8140b4ec77c 100644
--- a/lib/private/Log/Syslog.php
+++ b/lib/private/Log/Syslog.php
@@ -38,9 +38,12 @@ class Syslog extends LogDetails implements IWriter {
ILogger::FATAL => LOG_CRIT,
];
- public function __construct(SystemConfig $config) {
+ public function __construct(SystemConfig $config, ?string $tag = null) {
parent::__construct($config);
- openlog($config->getValue('syslog_tag', 'Nextcloud'), LOG_PID | LOG_CONS, LOG_USER);
+ if ($tag === null) {
+ $tag = $config->getValue('syslog_tag', 'Nextcloud');
+ }
+ openlog($tag, LOG_PID | LOG_CONS, LOG_USER);
}
public function __destruct() {
diff --git a/lib/private/Log/Systemdlog.php b/lib/private/Log/Systemdlog.php
index a01826c0b05..00f242e3718 100644
--- a/lib/private/Log/Systemdlog.php
+++ b/lib/private/Log/Systemdlog.php
@@ -56,14 +56,17 @@ class Systemdlog extends LogDetails implements IWriter {
protected $syslogId;
- public function __construct(SystemConfig $config) {
+ public function __construct(SystemConfig $config, ?string $tag = null) {
parent::__construct($config);
if (!function_exists('sd_journal_send')) {
throw new HintException(
'PHP extension php-systemd is not available.',
'Please install and enable PHP extension systemd if you wish to log to the Systemd journal.');
}
- $this->syslogId = $config->getValue('syslog_tag', 'Nextcloud');
+ if ($tag === null) {
+ $tag = $config->getValue('syslog_tag', 'Nextcloud');
+ }
+ $this->syslogId = $tag;
}
/**