Added Systemd.log documentation to config.sample.php

Changed name of default system (not systemd) logger from ownCloud to Nextcloud, to be consistent
Fixed license per https://github.com/nextcloud/server/pull/9760#discussion_r195026784
Pulled upstream updates

Signed-off-by: Johannes Ernst <jernst@indiecomputing.com>
This commit is contained in:
Johannes Ernst 2018-06-18 18:29:31 +00:00 committed by Arthur Schiwon
parent 0a65e62f29
commit 72340b2230
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
3 changed files with 29 additions and 11 deletions

View File

@ -710,18 +710,24 @@ $CONFIG = array(
*/ */
/** /**
* By default the Nextcloud logs are sent to the ``nextcloud.log`` file in the * This parameter determines where the Nextcloud logs are sent.
* default Nextcloud data directory. * ``file``: the logs are written to file ``nextcloud.log`` in the default
* If syslogging is desired, set this parameter to ``syslog``. * Nextcloud data directory. The log file can be changed with parameter
* Setting this parameter to ``errorlog`` will use the PHP error_log function * ``logfile``.
* for logging. * ``syslog``: the logs are sent to the system log. This requires a syslog daemon
* to be active.
* ``errorlog``: the logs are sent to the PHP ``error_log`` function.
* ``systemd``: the logs are sent to the Systemd journal. This requires a system
* that runs Systemd and the Systemd journal. The PHP extension ``systemd``
* must be installed and active.
* *
* Defaults to ``file`` * Defaults to ``file``
*/ */
'log_type' => 'file', 'log_type' => 'file',
/** /**
* Log file path for the Nextcloud logging type. * Name of the file to which the Nextcloud logs are written if parameter
* ``log_type`` is set to ``file``.
* *
* Defaults to ``[datadirectory]/nextcloud.log`` * Defaults to ``[datadirectory]/nextcloud.log``
*/ */
@ -738,7 +744,9 @@ $CONFIG = array(
/** /**
* If you maintain different instances and aggregate the logs, you may want * If you maintain different instances and aggregate the logs, you may want
* to distinguish between them. ``syslog_tag`` can be set per instance * to distinguish between them. ``syslog_tag`` can be set per instance
* with a unique id. Only available if ``log_type`` is set to ``syslog``. * with a unique id. Only available if ``log_type`` is set to ``syslog`` or
* ``systemd``.
*
* The default value is ``Nextcloud``. * The default value is ``Nextcloud``.
*/ */
'syslog_tag' => 'Nextcloud', 'syslog_tag' => 'Nextcloud',

View File

@ -39,7 +39,7 @@ class Syslog implements IWriter {
]; ];
public function __construct(IConfig $config) { public function __construct(IConfig $config) {
openlog($config->getSystemValue('syslog_tag', 'ownCloud'), LOG_PID | LOG_CONS, LOG_USER); openlog($config->getSystemValue('syslog_tag', 'Nextcloud'), LOG_PID | LOG_CONS, LOG_USER);
} }
public function __destruct() { public function __destruct() {

View File

@ -4,7 +4,7 @@
* *
* @author Johannes Ernst <jernst@indiecomputing.com> * @author Johannes Ernst <jernst@indiecomputing.com>
* *
* @license AGPL-3.0 * @license GNU AGPL version 3 or any later version
* *
* This code is free software: you can redistribute it and/or modify * This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3, * it under the terms of the GNU Affero General Public License, version 3,
@ -22,6 +22,7 @@
namespace OC\Log; namespace OC\Log;
use OC\HintException;
use OCP\ILogger; use OCP\ILogger;
use OCP\IConfig; use OCP\IConfig;
use OCP\Log\IWriter; use OCP\Log\IWriter;
@ -50,11 +51,20 @@ class Systemdlog implements IWriter {
ILogger::FATAL => 2, ILogger::FATAL => 2,
]; ];
protected $syslogId;
public function __construct(IConfig $config) { public function __construct(IConfig $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->getSystemValue('syslog_tag', 'Nextcloud');
} }
/** /**
* write a message in the log * Write a message to the log.
* @param string $app * @param string $app
* @param string $message * @param string $message
* @param int $level * @param int $level
@ -62,7 +72,7 @@ class Systemdlog implements IWriter {
public function write(string $app, $message, int $level) { public function write(string $app, $message, int $level) {
$journal_level = $this->levels[$level]; $journal_level = $this->levels[$level];
sd_journal_send('PRIORITY='.$journal_level, sd_journal_send('PRIORITY='.$journal_level,
'SYSLOG_IDENTIFIER=nextcloud', 'SYSLOG_IDENTIFIER='.$this->syslogId,
'MESSAGE={'.$app.'} '.$message); 'MESSAGE={'.$app.'} '.$message);
} }
} }