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

SimpleLogger   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A log() 0 3 2
A flush() 0 3 1
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