|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* AppserverIo\Logger\Handlers\DummyHandler |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link http://github.com/appserver-io/logger |
|
18
|
|
|
* @link http://www.appserver.io |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace AppserverIo\Logger\Handlers; |
|
22
|
|
|
|
|
23
|
|
|
use Psr\Log\LogLevel; |
|
24
|
|
|
use AppserverIo\Logger\LoggerUtils; |
|
25
|
|
|
use AppserverIo\Logger\LogMessageInterface; |
|
26
|
|
|
use AppserverIo\Logger\Formatters\FormatterInterface; |
|
27
|
|
|
use AppserverIo\Logger\Formatters\StandardFormatter; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* A dummy logger implementation. |
|
31
|
|
|
* |
|
32
|
|
|
* @author Tim Wagner <[email protected]> |
|
33
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
|
34
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
35
|
|
|
* @link http://github.com/appserver-io/logger |
|
36
|
|
|
* @link http://www.appserver.io |
|
37
|
|
|
*/ |
|
38
|
|
|
class DummyHandler implements HandlerInterface |
|
39
|
|
|
{ |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* The log level we want to use. |
|
43
|
|
|
* |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $logLevel; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* The available log levels. |
|
50
|
|
|
* |
|
51
|
|
|
* @var array |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $logLevels; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* The formatter instance. |
|
57
|
|
|
* |
|
58
|
|
|
* @var \AppserverIo\Logger\Formatters\FormatterInterface |
|
59
|
|
|
*/ |
|
60
|
|
|
protected $formatter; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Initializes the handler instance with channel name and log level. |
|
64
|
|
|
* |
|
65
|
|
|
* @param integer $logLevel The log level we want to use |
|
66
|
|
|
*/ |
|
67
|
10 |
|
public function __construct($logLevel = LogLevel::INFO) |
|
68
|
|
|
{ |
|
69
|
|
|
|
|
70
|
|
|
// initialize the available log levels and formatter |
|
71
|
10 |
|
$this->logLevels = LoggerUtils::$logLevels; |
|
72
|
10 |
|
$this->formatter = new StandardFormatter(); |
|
73
|
|
|
|
|
74
|
|
|
// set the actual log level |
|
75
|
10 |
|
$this->logLevel = $logLevel; |
|
|
|
|
|
|
76
|
10 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Sets the formatter for this handler. |
|
80
|
|
|
* |
|
81
|
|
|
* @param \AppserverIo\Logger\Formatters\FormatterInterface $formatter The formatter instance |
|
82
|
|
|
* |
|
83
|
|
|
* @return void |
|
84
|
|
|
*/ |
|
85
|
|
|
public function setFormatter(FormatterInterface $formatter) |
|
86
|
|
|
{ |
|
87
|
|
|
$this->formatter = $formatter; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Returns the formatter for this handler. |
|
92
|
|
|
* |
|
93
|
|
|
* @return \AppserverIo\Logger\Formatters\FormatterInterface The formatter instance |
|
94
|
|
|
*/ |
|
95
|
6 |
|
public function getFormatter() |
|
96
|
|
|
{ |
|
97
|
6 |
|
return $this->formatter; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Handles the log message. |
|
102
|
|
|
* |
|
103
|
|
|
* @param \AppserverIo\Logger\LogMessageInterface $logMessage The message to be handled |
|
104
|
|
|
* |
|
105
|
|
|
* @return void |
|
106
|
|
|
*/ |
|
107
|
2 |
|
public function handle(LogMessageInterface $logMessage) |
|
108
|
|
|
{ |
|
109
|
|
|
// this is a dummy logger |
|
110
|
2 |
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Returns the log level we want to use. |
|
114
|
|
|
* |
|
115
|
|
|
* @return integer The log level |
|
116
|
|
|
*/ |
|
117
|
6 |
|
protected function getLogLevel() |
|
118
|
|
|
{ |
|
119
|
6 |
|
return $this->logLevel; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Returns TRUE if the handler should log a message based on the actual |
|
124
|
|
|
* log level, else FALSE. |
|
125
|
|
|
* |
|
126
|
|
|
* @param string $level The log level to query |
|
127
|
|
|
* |
|
128
|
|
|
* @return boolean TRUE if the handler should log |
|
129
|
|
|
*/ |
|
130
|
6 |
|
protected function shouldLog($level) |
|
131
|
|
|
{ |
|
132
|
6 |
|
return $this->logLevels[$level] >= $this->logLevels[$this->getLogLevel()]; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.