Completed
Push — master ( a56ec1...2aa108 )
by Morris
44:44 queued 16:07
created

Syslog::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Bart Visscher <[email protected]>
6
 * @author Morris Jobke <[email protected]>
7
 * @author Roeland Jago Douma <[email protected]>
8
 * @author Thomas Müller <[email protected]>
9
 *
10
 * @license AGPL-3.0
11
 *
12
 * This code is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License, version 3,
14
 * as published by the Free Software Foundation.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License, version 3,
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
23
 *
24
 */
25
26
namespace OC\Log;
27
28
use OCP\ILogger;
29
use OCP\IConfig;
30
use OCP\Log\IWriter;
31
32
class Syslog implements IWriter {
33
	protected $levels = [
34
		ILogger::DEBUG => LOG_DEBUG,
35
		ILogger::INFO => LOG_INFO,
36
		ILogger::WARN => LOG_WARNING,
37
		ILogger::ERROR => LOG_ERR,
38
		ILogger::FATAL => LOG_CRIT,
39
	];
40
41
	public function __construct(IConfig $config) {
42
		openlog($config->getSystemValue('syslog_tag', 'ownCloud'), LOG_PID | LOG_CONS, LOG_USER);
43
	}
44
45
	public function __destruct() {
46
		closelog();
47
	}
48
49
	/**
50
	 * write a message in the log
51
	 * @param string $app
52
	 * @param string $message
53
	 * @param int $level
54
	 */
55
	public function write(string $app, $message, int $level) {
56
		$syslog_level = $this->levels[$level];
57
		syslog($syslog_level, '{'.$app.'} '.$message);
58
	}
59
}
60