1
|
|
|
<?php namespace Comodojo\Extender\Log; |
2
|
|
|
|
3
|
|
|
use \Monolog\Logger; |
4
|
|
|
use \Monolog\Handler\AbstractProcessingHandler; |
5
|
|
|
use \Console_Color2; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Log-to-console handler |
9
|
|
|
* |
10
|
|
|
* @package Comodojo extender |
11
|
|
|
* @author Marco Giovinazzi <[email protected]> |
12
|
|
|
* @license GPL-3.0+ |
13
|
|
|
* |
14
|
|
|
* LICENSE: |
15
|
|
|
* |
16
|
|
|
* This program is free software: you can redistribute it and/or modify |
17
|
|
|
* it under the terms of the GNU Affero General Public License as |
18
|
|
|
* published by the Free Software Foundation, either version 3 of the |
19
|
|
|
* License, or (at your option) any later version. |
20
|
|
|
* |
21
|
|
|
* This program is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU Affero General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* You should have received a copy of the GNU Affero General Public License |
27
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
class ConsoleHandler extends AbstractProcessingHandler { |
31
|
|
|
|
32
|
|
|
private $color = null; |
33
|
|
|
|
34
|
|
|
private static $colors = array( |
35
|
|
|
100 => '%8', |
36
|
|
|
200 => '%g', |
37
|
|
|
250 => '%U', |
38
|
|
|
300 => '%Y', |
39
|
|
|
400 => '%r', |
40
|
|
|
500 => '%R', |
41
|
|
|
550 => '%m', |
42
|
|
|
600 => '%M', |
43
|
|
|
); |
44
|
|
|
|
45
|
6 |
|
public function __construct($level = Logger::DEBUG, $bubble = true) { |
46
|
|
|
|
47
|
6 |
|
$this->color = new Console_Color2(); |
48
|
|
|
|
49
|
6 |
|
parent::__construct($level, $bubble); |
50
|
|
|
|
51
|
6 |
|
} |
52
|
|
|
|
53
|
|
|
protected function write(array $record) { |
54
|
|
|
|
55
|
|
|
$level = $record['level']; |
56
|
|
|
|
57
|
|
|
$message = $record['formatted']; |
58
|
|
|
|
59
|
|
|
$context = empty($record['context']) ? null : $record['context']; |
60
|
|
|
|
61
|
|
|
$time = $record['datetime']->format('c'); |
62
|
|
|
|
63
|
|
|
$this->toConsole($time, $level, $message, $context); |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
private function toConsole($time, $level, $message, $context) { |
|
|
|
|
68
|
|
|
|
69
|
|
|
print $this->color->convert(static::$colors[$level].$message."%n"); |
|
|
|
|
70
|
|
|
|
71
|
|
|
if ( !empty($context) ) print $this->color->convert(static::$colors[$level].var_export($context, true)."%n\n"); |
|
|
|
|
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.