Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Logger
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 level
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 error
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Dynart\Micro;
4
5use Katzgrau\KLogger\Logger as KLogger;
6
7class Logger extends KLogger implements LoggerInterface {
8
9    const CONFIG_DIR = 'log.dir';
10    const DEFAULT_DIR = 'logs';
11
12    const CONFIG_LEVEL = 'log.level';
13    const DEFAULT_LEVEL = 'error';
14
15    const CONFIG_OPTIONS = 'log.options';
16    const DEFAULT_OPTIONS = [];
17
18    const DEBUG = 'debug';
19    const INFO = 'info';
20    const WARNING = 'warning';
21    const ERROR = 'error';
22
23    private string $level;
24
25    public function __construct(ConfigInterface $config) {
26        parent::__construct(
27            $config->get(self::CONFIG_DIR, self::DEFAULT_DIR),
28            $config->get(self::CONFIG_LEVEL, self::DEFAULT_LEVEL),
29            $config->getArray(self::CONFIG_OPTIONS, self::DEFAULT_OPTIONS)
30        );
31        $this->level = $config->get(self::CONFIG_LEVEL, self::DEFAULT_LEVEL);
32    }
33
34    public function level(): string {
35        return $this->level;
36    }
37
38    public function error($message, array $context = array()) {
39        parent::error($message, $context);
40        error_log($message); // always log errors
41    }
42}