SimpleLogger   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

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

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
	private $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
	 * @param mixed[] $context
27
	 * @suppress PhanUnusedPublicMethodParameter
28
	 */
29
	public function log( $level, $message, array $context = [] ): void {
30
		if ( $this->levelToInt( $level ) >= $this->minLevel ) {
31
			echo $this->getFormattedMessage( $level, $message ) . "\n";
32
		}
33
	}
34
35
	/**
36
	 * @inheritDoc
37
	 */
38
	public function flush(): void {
39
		// Everything else is printed immediately
40
		echo "\n" . str_repeat( '-', 80 ) . "\n\n";
41
	}
42
}
43