1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2018 Arthur Schiwon <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Arthur Schiwon <[email protected]> |
6
|
|
|
* @author Johannes Ernst <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @license GNU AGPL version 3 or any later version |
9
|
|
|
* |
10
|
|
|
* This program is free software: you can redistribute it and/or modify |
11
|
|
|
* it under the terms of the GNU Affero General Public License as |
12
|
|
|
* published by the Free Software Foundation, either version 3 of the |
13
|
|
|
* License, or (at your option) any later version. |
14
|
|
|
* |
15
|
|
|
* This program is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU Affero General Public License for more details. |
19
|
|
|
* |
20
|
|
|
* You should have received a copy of the GNU Affero General Public License |
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace OC\Log; |
26
|
|
|
|
27
|
|
|
use OC\Log; |
28
|
|
|
use OC\SystemConfig; |
29
|
|
|
use OCP\ILogger; |
30
|
|
|
use OCP\IServerContainer; |
31
|
|
|
use OCP\Log\ILogFactory; |
32
|
|
|
use OCP\Log\IWriter; |
33
|
|
|
|
34
|
|
|
class LogFactory implements ILogFactory { |
35
|
|
|
/** @var IServerContainer */ |
36
|
|
|
private $c; |
37
|
|
|
/** @var SystemConfig */ |
38
|
|
|
private $systemConfig; |
39
|
|
|
|
40
|
|
|
public function __construct(IServerContainer $c, SystemConfig $systemConfig) { |
41
|
|
|
$this->c = $c; |
42
|
|
|
$this->systemConfig = $systemConfig; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @throws \OCP\AppFramework\QueryException |
47
|
|
|
*/ |
48
|
|
|
public function get(string $type):IWriter { |
49
|
|
|
switch (strtolower($type)) { |
50
|
|
|
case 'errorlog': |
51
|
|
|
return new Errorlog(); |
52
|
|
|
case 'syslog': |
53
|
|
|
return $this->c->resolve(Syslog::class); |
54
|
|
|
case 'systemd': |
55
|
|
|
return $this->c->resolve(Systemdlog::class); |
56
|
|
|
case 'file': |
57
|
|
|
return $this->buildLogFile(); |
58
|
|
|
|
59
|
|
|
// Backwards compatibility for old and fallback for unknown log types |
60
|
|
|
case 'owncloud': |
61
|
|
|
case 'nextcloud': |
62
|
|
|
default: |
63
|
|
|
return $this->buildLogFile(); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getCustomLogger(string $path):ILogger { |
68
|
|
|
$log = $this->buildLogFile($path); |
69
|
|
|
return new Log($log, $this->systemConfig); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
protected function buildLogFile(string $logFile = ''):File { |
73
|
|
|
$defaultLogFile = $this->systemConfig->getValue('datadirectory', \OC::$SERVERROOT.'/data').'/nextcloud.log'; |
74
|
|
|
if($logFile === '') { |
75
|
|
|
$logFile = $this->systemConfig->getValue('logfile', $defaultLogFile); |
76
|
|
|
} |
77
|
|
|
$fallback = $defaultLogFile !== $logFile ? $defaultLogFile : ''; |
78
|
|
|
|
79
|
|
|
return new File($logFile, $fallback, $this->systemConfig); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|