Skip to content

Commit 497c584

Browse files
committed
Allow write audit log to syslog and systemdlog
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 4c41abd commit 497c584

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
@@ -839,6 +839,13 @@
839839
*/
840840
'log_type' => 'file',
841841

842+
/**
843+
* This parameter determines where the audit logs are sent. See ``log_type`` for more information.
844+
*
845+
* Defaults to ``file``
846+
*/
847+
'log_type_audit' => 'file',
848+
842849
/**
843850
* Name of the file to which the Nextcloud logs are written if parameter
844851
* ``log_type`` is set to ``file``.
@@ -848,7 +855,15 @@
848855
'logfile' => '/var/log/nextcloud.log',
849856

850857
/**
851-
* Log file mode for the Nextcloud loggin type in octal notation.
858+
* Name of the file to which the audit logs are written if parameter
859+
* ``log_type`` is set to ``file``.
860+
*
861+
* Defaults to ``[datadirectory]/audit.log``
862+
*/
863+
'logfile_audit' => '/var/log/audit.log',
864+
865+
/**
866+
* Log file mode for the Nextcloud logging type in octal notation.
852867
*
853868
* Defaults to 0640 (writeable by user, readable by group).
854869
*/
@@ -872,6 +887,16 @@
872887
*/
873888
'syslog_tag' => 'Nextcloud',
874889

890+
/**
891+
* If you maintain different instances and aggregate the logs, you may want
892+
* to distinguish between them. ``syslog_tag_audit`` can be set per instance
893+
* with a unique id. Only available if ``log_type`` is set to ``syslog`` or
894+
* ``systemd``.
895+
*
896+
* The default value is the value of ``syslog_tag``.
897+
*/
898+
'syslog_tag_audit' => 'Nextcloud',
899+
875900
/**
876901
* Log condition for log level increase based on conditions. Once one of these
877902
* conditions is met, the required log level is set to debug. This allows to

0 commit comments

Comments
 (0)