Passed
Push — master ( 3d4f1f...2a2d37 )
by Daimona
01:36
created

SimpleLogger::flush()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare( strict_types=1 );
2
3
namespace BotRiconferme\Logger;
4
5
use Psr\Log\AbstractLogger;
6
use Psr\Log\LogLevel;
7
8
/**
9
 * Logger that just prints stuff to stdout
10
 */
11
class SimpleLogger extends AbstractLogger implements IFlushingAwareLogger {
12
	use LoggerTrait;
13
14
	/** @var int */
15
	protected $minLevel;
16
17
	/**
18
	 * @param string $minlevel
19
	 */
20
	public function __construct( $minlevel = LogLevel::INFO ) {
21
		$this->minLevel = $this->levelToInt( $minlevel );
22
	}
23
24
	/**
25
	 * @inheritDoc
26
	 * @suppress PhanUnusedPublicMethodParameter
27
	 */
28
	public function log( $level, $message, array $context = [] ) {
29
		if ( $this->levelToInt( $level ) >= $this->minLevel ) {
30
			echo $this->getFormattedMessage( $level, $message ) . "\n";
31
		}
32
	}
33
34
	/**
35
	 * @inheritDoc
36
	 */
37
	public function flush() : void {
38
		// Everything else is printed immediately
39
		echo "\n" . str_repeat( '-', 80 ) . "\n\n";
40
	}
41
}
42