Completed
Push — master ( 9e80c6...352db1 )
by Dmitry
02:36
created

EchoLog::checkLevel()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 12
nc 2
nop 1
1
<?php
2
/**
3
 * @author Dmitry Gladyshev <[email protected]>
4
 * @created 02.11.16 13:52
5
 */
6
7
namespace Yandex\Direct\Logger;
8
9
use Psr\Log\AbstractLogger;
10
use Psr\Log\LogLevel;
11
use Psr\Log\InvalidArgumentException;
12
13
/**
14
 * Class EchoLog
15
 * @package Yandex\Direct\Logger
16
 */
17
class EchoLog extends AbstractLogger
18
{
19
    /**
20
     * @param string $level
21
     * @param string $message
22
     * @param array $context
23
     * @throws InvalidArgumentException
24
     */
25
    public function log($level, $message, array $context = [])
26
    {
27
        if (!$this->checkLevel($level)) {
28
            throw new InvalidArgumentException("Invalid log level {$level}");
29
        }
30
        echo "[$level] $message" . PHP_EOL;
31
    }
32
33
    private function checkLevel($level)
34
    {
35
        if (in_array($level, [
36
            LogLevel::ALERT,
37
            LogLevel::CRITICAL,
38
            LogLevel::EMERGENCY,
39
            LogLevel::ERROR,
40
            LogLevel::WARNING,
41
            LogLevel::DEBUG,
42
            LogLevel::INFO,
43
            LogLevel::NOTICE,
44
        ])) {
45
            return true;
46
        }
47
        return false;
48
    }
49
}
50