Skip to content

Commit 5271bd1

Browse files
nickvergessenPVince81
authored andcommitted
Allow write audit log to syslog and systemdlog
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 67a8d3f commit 5271bd1

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

apps/admin_audit/lib/AppInfo/Application.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,19 @@ public function boot(IBootContext $context): void {
9696
}
9797

9898
private function getLogger(IConfig $config,
99-
LoggerInterface $logger,
10099
ILogFactory $logFactory): LoggerInterface {
101-
$default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
102-
$logFile = $config->getAppValue('admin_audit', 'logfile', $default);
103-
104-
if ($logFile === null) {
105-
return $logger;
100+
$auditType = $config->getSystemValueString('log_type_audit', 'file');
101+
$defaultTag = $config->getSystemValueString('syslog_tag', 'Nextcloud');
102+
$auditTag = $config->getSystemValueString('syslog_tag_audit', $defaultTag);
103+
$logFile = $config->getSystemValueString('logfile_audit', '');
104+
105+
if ($auditType === 'file' && !$logFile) {
106+
$default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
107+
// Legacy way was appconfig, now it's paralleled with the normal log config
108+
$logFile = $config->getAppValue('admin_audit', 'logfile', $default);
106109
}
107-
return $logFactory->getCustomPsrLogger($logFile);
110+
111+
return $logFactory->getCustomPsrLogger($logFile, $auditType, $auditTag);
108112
}
109113

110114
/**

config/config.sample.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,13 @@
849849
*/
850850
'log_type' => 'file',
851851

852+
/**
853+
* This parameter determines where the audit logs are sent. See ``log_type`` for more information.
854+
*
855+
* Defaults to ``file``
856+
*/
857+
'log_type_audit' => 'file',
858+
852859
/**
853860
* Name of the file to which the Nextcloud logs are written if parameter
854861
* ``log_type`` is set to ``file``.
@@ -858,7 +865,15 @@
858865
'logfile' => '/var/log/nextcloud.log',
859866

860867
/**
861-
* Log file mode for the Nextcloud loggin type in octal notation.
868+
* Name of the file to which the audit logs are written if parameter
869+
* ``log_type`` is set to ``file``.
870+
*
871+
* Defaults to ``[datadirectory]/audit.log``
872+
*/
873+
'logfile_audit' => '/var/log/audit.log',
874+
875+
/**
876+
* Log file mode for the Nextcloud logging type in octal notation.
862877
*
863878
* Defaults to 0640 (writeable by user, readable by group).
864879
*/
@@ -882,6 +897,16 @@
882897
*/
883898
'syslog_tag' => 'Nextcloud',
884899

900+
/**
901+
* If you maintain different instances and aggregate the logs, you may want
902+
* to distinguish between them. ``syslog_tag_audit`` can be set per instance
903+
* with a unique id. Only available if ``log_type`` is set to ``syslog`` or
904+
* ``systemd``.
905+
*
906+
* The default value is the value of ``syslog_tag``.
907+
*/
908+
'syslog_tag_audit' => 'Nextcloud',
909+
885910
/**
886911
* Log condition for log level increase based on conditions. Once one of these
887912
* conditions is met, the required log level is set to debug. This allows to

0 commit comments

Comments
 (0)