Completed
Push — master ( 82da5d...012a80 )
by Charlotte
10s
created

SimpleLogger::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This file is a part of Woketo package.
4
 *
5
 * (c) Nekland <[email protected]>
6
 *
7
 * For the full license, take a look to the LICENSE file
8
 * on the root directory of this project
9
 */
10
11
namespace Nekland\Woketo\Utils;
12
13
14
use Psr\Log\AbstractLogger;
15
use Psr\Log\LogLevel;
16
17
class SimpleLogger extends AbstractLogger
18
{
19
    /**
20
     * Modify the log behavior
21
     * @var bool
22
     */
23
    private $debug;
24
25 2
    public function __construct($debug = false)
26
    {
27 2
        $this->debug = $debug;
28 2
    }
29
30
    /**
31
     * Log
32
     *
33
     * @param mixed  $level
34
     * @param string $message
35
     * @param array  $context
36
     */
37 2
    public function log($level, $message, array $context = array())
38
    {
39
        // Doesn't log everything in not debug context
40 2
        if ($this->debug || \in_array($level, [LogLevel::CRITICAL, LogLevel::ERROR])) {
41 2
            echo '[' . date('Y-m-d H:i:s') . '][' . $level . '] ' . $message ."\n";
42
        }
43 2
    }
44
}
45