| Total Complexity | 7 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Coverage | 45.45% |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | final class LoggerUtil implements LoggerUtilInterface |
||
| 12 | { |
||
| 13 | private ConfigInterface $config; |
||
| 14 | |||
| 15 | private $logger; |
||
| 16 | |||
| 17 | private int $level; |
||
| 18 | |||
| 19 | private bool $doLog; |
||
| 20 | |||
| 21 | 1 | public function __construct(ConfigInterface $config) |
|
| 22 | { |
||
| 23 | 1 | $this->config = $config; |
|
| 24 | 1 | $this->doLog = false; |
|
| 25 | } |
||
| 26 | |||
| 27 | 1 | public function init(string $channel = 'stu', int $level = LoggerEnum::LEVEL_INFO): void |
|
| 28 | { |
||
| 29 | 1 | $this->level = $level; |
|
| 30 | |||
| 31 | 1 | if ($this->checkDoLog()) { |
|
| 32 | $this->logger = new Logger($channel); |
||
| 33 | $this->logger->pushHandler( |
||
| 34 | new StreamHandler( |
||
| 35 | $this->config->get('debug.logfile_path') |
||
| 36 | ), |
||
| 37 | ); |
||
| 38 | } |
||
| 39 | } |
||
| 40 | |||
| 41 | 1 | private function checkDoLog(): bool |
|
| 42 | { |
||
| 43 | 1 | $threshold = (int) $this->config->get('debug.loglevel'); |
|
| 44 | |||
| 45 | 1 | $this->doLog = $threshold <= $this->level; |
|
| 46 | |||
| 47 | 1 | return $this->doLog; |
|
| 48 | } |
||
| 49 | |||
| 50 | public function doLog(): bool |
||
| 53 | } |
||
| 54 | |||
| 55 | public function log(string $message): void |
||
| 56 | { |
||
| 63 |