1
|
|
|
<?php namespace Comodojo\Dispatcher\Log;
|
2
|
|
|
|
3
|
|
|
use \Monolog\Logger;
|
4
|
|
|
use \Monolog\Handler\StreamHandler;
|
5
|
|
|
use \Monolog\Handler\NullHandler;
|
6
|
|
|
|
7
|
|
|
/**
|
8
|
|
|
*
|
9
|
|
|
*
|
10
|
|
|
* @package Comodojo Framework
|
11
|
|
|
* @author Marco Giovinazzi <[email protected]>
|
12
|
|
|
* @author Marco Castiello <[email protected]>
|
13
|
|
|
* @license GPL-3.0+
|
14
|
|
|
*
|
15
|
|
|
* LICENSE:
|
16
|
|
|
*
|
17
|
|
|
* This program is free software: you can redistribute it and/or modify
|
18
|
|
|
* it under the terms of the GNU Affero General Public License as
|
19
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
20
|
|
|
* License, or (at your option) any later version.
|
21
|
|
|
*
|
22
|
|
|
* This program is distributed in the hope that it will be useful,
|
23
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
24
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
25
|
|
|
* GNU Affero General Public License for more details.
|
26
|
|
|
*
|
27
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
28
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
29
|
|
|
*/
|
30
|
|
|
|
31
|
|
|
class DispatcherLogger {
|
32
|
|
|
|
33
|
|
|
/**
|
34
|
|
|
* Create the logger
|
35
|
|
|
*
|
36
|
|
|
* @param bool $verbose
|
|
|
|
|
37
|
|
|
*
|
38
|
|
|
* @return \Monolog\Logger
|
39
|
|
|
*/
|
40
|
|
|
public static function create(Configuration $configuration) {
|
41
|
|
|
|
42
|
|
|
$name = $configuration->get('dispatcher-log-name');
|
43
|
|
|
|
44
|
|
|
$enabled = $configuration->get('dispatcher-log-enabled');
|
45
|
|
|
|
46
|
|
|
$level = self::getLevel( $configuration->get('dispatcher-log-level') );
|
47
|
|
|
|
48
|
|
|
$target = $configuration->get('dispatcher-log-target');
|
49
|
|
|
|
50
|
|
|
$logger = new Logger($name);
|
51
|
|
|
|
52
|
|
|
if ( $enabled === true ) {
|
53
|
|
|
|
54
|
|
|
$logger->pushHandler( new StreamHandler( $target, $level) );
|
55
|
|
|
|
56
|
|
|
} else {
|
57
|
|
|
|
58
|
|
|
$logger->pushHandler( new NullHandler($level) );
|
59
|
|
|
|
60
|
|
|
}
|
61
|
|
|
|
62
|
|
|
return $logger;
|
63
|
|
|
|
64
|
|
|
}
|
65
|
|
|
|
66
|
|
|
/**
|
67
|
|
|
* Map provided log level to level code
|
68
|
|
|
*
|
69
|
|
|
* @param string $level
|
70
|
|
|
*
|
71
|
|
|
* @return integer
|
72
|
|
|
*/
|
73
|
|
|
protected static function getLevel($level) {
|
74
|
|
|
|
75
|
|
|
switch ( strtoupper($level) ) {
|
76
|
|
|
|
77
|
|
|
case 'INFO':
|
78
|
|
|
$logger_level = Logger::INFO;
|
79
|
|
|
break;
|
80
|
|
|
|
81
|
|
|
case 'NOTICE':
|
82
|
|
|
$logger_level = Logger::NOTICE;
|
83
|
|
|
break;
|
84
|
|
|
|
85
|
|
|
case 'WARNING':
|
86
|
|
|
$logger_level = Logger::WARNING;
|
87
|
|
|
break;
|
88
|
|
|
|
89
|
|
|
case 'ERROR':
|
90
|
|
|
$logger_level = Logger::ERROR;
|
91
|
|
|
break;
|
92
|
|
|
|
93
|
|
|
case 'CRITICAL':
|
94
|
|
|
$logger_level = Logger::CRITICAL;
|
95
|
|
|
break;
|
96
|
|
|
|
97
|
|
|
case 'ALERT':
|
98
|
|
|
$logger_level = Logger::ALERT;
|
99
|
|
|
break;
|
100
|
|
|
|
101
|
|
|
case 'EMERGENCY':
|
102
|
|
|
$logger_level = Logger::EMERGENCY;
|
103
|
|
|
break;
|
104
|
|
|
|
105
|
|
|
case 'DEBUG':
|
106
|
|
|
default:
|
107
|
|
|
$logger_level = Logger::DEBUG;
|
108
|
|
|
break;
|
109
|
|
|
|
110
|
|
|
}
|
111
|
|
|
|
112
|
|
|
return $logger_level;
|
113
|
|
|
|
114
|
|
|
}
|
115
|
|
|
|
116
|
|
|
} |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.