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

LogOutputAbstract::log()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 2
nc 2
nop 3
crap 30
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