|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2022 Carl Schwan <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Carl Schwan <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OCA\AdminAudit; |
|
25
|
|
|
|
|
26
|
|
|
use OCP\IConfig; |
|
27
|
|
|
use OCP\Log\ILogFactory; |
|
28
|
|
|
use Psr\Log\LoggerInterface; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Logger that logs in the audit log file instead of the normal log file |
|
32
|
|
|
*/ |
|
33
|
|
|
class AuditLogger implements IAuditLogger { |
|
34
|
|
|
|
|
35
|
|
|
/** @var LoggerInterface */ |
|
36
|
|
|
private $parentLogger; |
|
37
|
|
|
|
|
38
|
|
|
public function __construct(ILogFactory $logFactory, IConfig $config) { |
|
39
|
|
|
$auditType = $config->getSystemValueString('log_type_audit', 'file'); |
|
40
|
|
|
$defaultTag = $config->getSystemValueString('syslog_tag', 'Nextcloud'); |
|
41
|
|
|
$auditTag = $config->getSystemValueString('syslog_tag_audit', $defaultTag); |
|
42
|
|
|
$logFile = $config->getSystemValueString('logfile_audit', ''); |
|
43
|
|
|
|
|
44
|
|
|
if ($auditType === 'file' && !$logFile) { |
|
45
|
|
|
$default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log'; |
|
46
|
|
|
// Legacy way was appconfig, now it's paralleled with the normal log config |
|
47
|
|
|
$logFile = $config->getAppValue('admin_audit', 'logfile', $default); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$this->parentLogger = $logFactory->getCustomPsrLogger($logFile, $auditType, $auditTag); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function emergency($message, array $context = array()) { |
|
54
|
|
|
$this->parentLogger->emergency($message, $context); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function alert($message, array $context = array()) { |
|
58
|
|
|
$this->parentLogger->alert($message, $context); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function critical($message, array $context = array()) { |
|
62
|
|
|
$this->parentLogger->critical($message, $context); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function error($message, array $context = array()) { |
|
66
|
|
|
$this->parentLogger->error($message, $context); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function warning($message, array $context = array()) { |
|
70
|
|
|
$this->parentLogger->warning($message, $context); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function notice($message, array $context = array()) { |
|
74
|
|
|
$this->parentLogger->notice($message, $context); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function info($message, array $context = array()) { |
|
78
|
|
|
$this->parentLogger->info($message, $context); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function debug($message, array $context = array()) { |
|
82
|
|
|
$this->parentLogger->debug($message, $context); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function log($level, $message, array $context = array()) { |
|
86
|
|
|
$this->parentLogger->log($level, $message, $context); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|