|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* WebHemi. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5.6 |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright 2012 - 2016 Gixx-web (http://www.gixx-web.com) |
|
8
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
|
9
|
|
|
* |
|
10
|
|
|
* @link http://www.gixx-web.com |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace WebHemi\Adapter\Log\Klogger; |
|
14
|
|
|
|
|
15
|
|
|
use Katzgrau\KLogger\Logger; |
|
16
|
|
|
use Psr\Log\LogLevel; |
|
17
|
|
|
use WebHemi\Adapter\Log\LogAdapterInterface; |
|
18
|
|
|
use WebHemi\Config\ConfigInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class KloggerAdapter |
|
22
|
|
|
*/ |
|
23
|
|
|
class KloggerAdapter extends LogLevel implements LogAdapterInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var Logger */ |
|
26
|
|
|
private $adapter; |
|
27
|
|
|
/** @var array */ |
|
28
|
|
|
private $configuration; |
|
29
|
|
|
/** @var array */ |
|
30
|
|
|
private $logLevel = [ |
|
31
|
|
|
0 => self::DEBUG, |
|
32
|
|
|
1 => self::INFO, |
|
33
|
|
|
2 => self::NOTICE, |
|
34
|
|
|
3 => self::WARNING, |
|
35
|
|
|
4 => self::ERROR, |
|
36
|
|
|
5 => self::CRITICAL, |
|
37
|
|
|
6 => self::ALERT, |
|
38
|
|
|
7 => self::EMERGENCY, |
|
39
|
|
|
]; |
|
40
|
|
|
private $defaultLevel = self::WARNING; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* LogAdapterInterface constructor. |
|
44
|
|
|
* |
|
45
|
|
|
* @param ConfigInterface $configuration |
|
46
|
|
|
* @param string $section |
|
47
|
|
|
*/ |
|
48
|
2 |
|
public function __construct(ConfigInterface $configuration, $section) |
|
49
|
|
|
{ |
|
50
|
2 |
|
$this->configuration = $configuration->getData('logging/'.$section); |
|
|
|
|
|
|
51
|
|
|
|
|
52
|
2 |
|
$logPath = $this->configuration['path']; |
|
53
|
2 |
|
$logLevel = $this->logLevel[$this->configuration['log_level']]; |
|
54
|
|
|
$options = [ |
|
55
|
2 |
|
'prefix' => $this->configuration['file_name'], |
|
56
|
2 |
|
'extension' => $this->configuration['file_extension'], |
|
57
|
2 |
|
'dateFormat' => $this->configuration['date_format'] |
|
58
|
2 |
|
]; |
|
59
|
|
|
|
|
60
|
2 |
|
$this->adapter = new Logger($logPath, $logLevel, $options); |
|
61
|
2 |
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Logs with an arbitrary level. |
|
65
|
|
|
* |
|
66
|
|
|
* @param mixed $level |
|
67
|
|
|
* @param string $message |
|
68
|
|
|
* @param array $context |
|
69
|
|
|
*/ |
|
70
|
1 |
|
public function log($level, $message, array $context = []) |
|
71
|
|
|
{ |
|
72
|
1 |
|
if (is_numeric($level)) { |
|
73
|
1 |
|
$level = isset($this->logLevel[$level]) ? $this->logLevel[$level] : $this->defaultLevel; |
|
74
|
1 |
|
} elseif (!in_array($level, $this->logLevel)) { |
|
75
|
1 |
|
$level = $this->defaultLevel; |
|
76
|
1 |
|
} |
|
77
|
|
|
|
|
78
|
1 |
|
$this->adapter->log($level, $message, $context); |
|
79
|
1 |
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..