Passed
Branch master (5c167b)
by smiley
02:26
created

LogOutputAbstract::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 2
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Class LogOutputAbstract
4
 *
5
 * @filesource   LogOutputAbstract.php
6
 * @created      04.01.2018
7
 * @package      chillerlan\Logger\Output
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2018 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\Logger\Output;
14
15
use chillerlan\Logger\LogOptions;
16
17
/**
18
 *
19
 */
20
abstract class LogOutputAbstract implements LogOutputInterface{
21
22
	/**
23
	 * @var \chillerlan\Logger\LogOptions
24
	 */
25
	protected $options;
26
27 1
	public function __construct(LogOptions $options = null){
28 1
		$this->options = $options ?? new LogOptions;
29 1
	}
30
31
	public function __destruct(){
32
		$this->close();
33
	}
34
35
	public function close():LogOutputInterface{
36
		return $this;
37
	}
38
39
	abstract protected function __log(string $level, string $message, array $context = null);
40
41
	public function log(string $level, string $message, array $context = null){ // @todo: loglevel bitmask
42
		if((array_key_exists($level, $this::LEVELS) && $this::LEVELS[$level] >= $this::LEVELS[$this->options->minLogLevel]) || (!array_key_exists($level, $this::LEVELS) && !empty($level))){
43
			$this->__log($level, $message, $context);
44
		}
45
	}
46
47
}
48