@@ -17,14 +17,14 @@ discard block |
||
17 | 17 | |
18 | 18 | class LogLaddy implements LoggerInterface |
19 | 19 | { |
20 | - use \Psr\Log\LoggerTrait; // PSR implementation |
|
20 | + use \Psr\Log\LoggerTrait; // PSR implementation |
|
21 | 21 | |
22 | - public const REPORTING_USER = 'user_messages'; |
|
23 | - public const INTERNAL_ERROR = 'error'; |
|
24 | - public const USER_EXCEPTION = 'exception'; |
|
25 | - public const LOG_LEVEL_SUCCESS = 'ok'; |
|
22 | + public const REPORTING_USER='user_messages'; |
|
23 | + public const INTERNAL_ERROR='error'; |
|
24 | + public const USER_EXCEPTION='exception'; |
|
25 | + public const LOG_LEVEL_SUCCESS='ok'; |
|
26 | 26 | |
27 | - private $has_halting_messages = false; |
|
27 | + private $has_halting_messages=false; |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Everything went fine, which is always nice. |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @return void |
36 | 36 | */ |
37 | - public function nice($message, array $context = array()) |
|
37 | + public function nice($message, array $context=array()) |
|
38 | 38 | { |
39 | 39 | $this->log(LogLevel::NICE, $message, $context); |
40 | 40 | } |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | * handler for errors |
57 | 57 | * use set_error_handler('\HexMakina\kadro\Logger\LogLaddy::error_handler') |
58 | 58 | */ |
59 | - public function error_handler($level, $message, $file = '', $line = 0) |
|
59 | + public function error_handler($level, $message, $file='', $line=0) |
|
60 | 60 | { |
61 | - $loglevel = self::map_error_level_to_log_level($level); |
|
61 | + $loglevel=self::map_error_level_to_log_level($level); |
|
62 | 62 | $this->$loglevel($message, ['file' => $file, 'line' => $line, 'trace' => debug_backtrace()]); |
63 | 63 | } |
64 | 64 | |
@@ -92,22 +92,22 @@ discard block |
||
92 | 92 | |
93 | 93 | // -- Implementation of LoggerInterface::log(), all other methods are in LoggerTrait |
94 | 94 | |
95 | - public function log($level, $message, array $context = []) |
|
95 | + public function log($level, $message, array $context=[]) |
|
96 | 96 | { |
97 | - $display_error = null; |
|
97 | + $display_error=null; |
|
98 | 98 | |
99 | 99 | // --- Handles Throwables (exception_handler()) |
100 | 100 | if ($message === self::INTERNAL_ERROR || $message === self::USER_EXCEPTION) { |
101 | - $this->has_halting_messages = true; |
|
102 | - if (($context = current($context)) !== false) { |
|
103 | - $display_error = Debugger::formatThrowable($context); |
|
104 | - $display_error .= PHP_EOL.Debugger::tracesToString($context->getTrace(), false); |
|
101 | + $this->has_halting_messages=true; |
|
102 | + if (($context=current($context)) !== false) { |
|
103 | + $display_error=Debugger::formatThrowable($context); |
|
104 | + $display_error.=PHP_EOL.Debugger::tracesToString($context->getTrace(), false); |
|
105 | 105 | error_log($display_error); |
106 | 106 | self::HTTP_500($display_error); |
107 | 107 | } |
108 | 108 | } elseif ($this->system_halted($level)) { // analyses error level |
109 | - $display_error = sprintf( |
|
110 | - PHP_EOL . '%s in file %s:%d' . PHP_EOL . '%s', |
|
109 | + $display_error=sprintf( |
|
110 | + PHP_EOL.'%s in file %s:%d'.PHP_EOL.'%s', |
|
111 | 111 | $level, |
112 | 112 | Debugger::formatFilename($context['file']), |
113 | 113 | $context['line'], |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | |
117 | 117 | error_log($display_error); |
118 | 118 | |
119 | - $display_error .= PHP_EOL.Debugger::tracesToString($context['trace'], true); |
|
119 | + $display_error.=PHP_EOL.Debugger::tracesToString($context['trace'], true); |
|
120 | 120 | self::HTTP_500($display_error); |
121 | 121 | } else {// --- Handles user messages, through SESSION storage |
122 | 122 | $this->report_to_user($level, $message, $context); |
@@ -138,17 +138,17 @@ discard block |
||
138 | 138 | // -- User messages |
139 | 139 | |
140 | 140 | // -- User messages:add one |
141 | - public function report_to_user($level, $message, $context = []) |
|
141 | + public function report_to_user($level, $message, $context=[]) |
|
142 | 142 | { |
143 | 143 | if (!isset($_SESSION[self::REPORTING_USER])) { |
144 | - $_SESSION[self::REPORTING_USER] = []; |
|
144 | + $_SESSION[self::REPORTING_USER]=[]; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | if (!isset($_SESSION[self::REPORTING_USER][$level])) { |
148 | - $_SESSION[self::REPORTING_USER][$level] = []; |
|
148 | + $_SESSION[self::REPORTING_USER][$level]=[]; |
|
149 | 149 | } |
150 | 150 | |
151 | - $_SESSION[self::REPORTING_USER][$level][] = [$message, $context]; |
|
151 | + $_SESSION[self::REPORTING_USER][$level][]=[$message, $context]; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | // -- User messages:get all |
@@ -177,24 +177,24 @@ discard block |
||
177 | 177 | private static function map_error_level_to_log_level($level): string |
178 | 178 | { |
179 | 179 | // http://php.net/manual/en/errorfunc.constants.php |
180 | - $m = []; |
|
180 | + $m=[]; |
|
181 | 181 | |
182 | - $m[E_ERROR] = $m[E_PARSE] = $m[E_CORE_ERROR] = $m[E_COMPILE_ERROR] = $m[E_USER_ERROR] = $m[E_RECOVERABLE_ERROR] = LogLevel::ALERT; |
|
183 | - $m[1] = $m[4] = $m[16] = $m[64] = $m[256] = $m[4096] = LogLevel::ALERT; |
|
182 | + $m[E_ERROR]=$m[E_PARSE]=$m[E_CORE_ERROR]=$m[E_COMPILE_ERROR]=$m[E_USER_ERROR]=$m[E_RECOVERABLE_ERROR]=LogLevel::ALERT; |
|
183 | + $m[1]=$m[4]=$m[16]=$m[64]=$m[256]=$m[4096]=LogLevel::ALERT; |
|
184 | 184 | |
185 | - $m[E_WARNING] = $m[E_CORE_WARNING] = $m[E_COMPILE_WARNING] = $m[E_USER_WARNING] = LogLevel::CRITICAL; |
|
186 | - $m[2] = $m[32] = $m[128] = $m[512] = LogLevel::CRITICAL; |
|
185 | + $m[E_WARNING]=$m[E_CORE_WARNING]=$m[E_COMPILE_WARNING]=$m[E_USER_WARNING]=LogLevel::CRITICAL; |
|
186 | + $m[2]=$m[32]=$m[128]=$m[512]=LogLevel::CRITICAL; |
|
187 | 187 | |
188 | - $m[E_NOTICE] = $m[E_USER_NOTICE] = LogLevel::ERROR; |
|
189 | - $m[8] = $m[1024] = LogLevel::ERROR; |
|
188 | + $m[E_NOTICE]=$m[E_USER_NOTICE]=LogLevel::ERROR; |
|
189 | + $m[8]=$m[1024]=LogLevel::ERROR; |
|
190 | 190 | |
191 | - $m[E_STRICT] = $m[E_DEPRECATED] = $m[E_USER_DEPRECATED] = $m[E_ALL] = LogLevel::DEBUG; |
|
192 | - $m[2048] = $m[8192] = $m[16384] = $m[32767] = LogLevel::DEBUG; |
|
191 | + $m[E_STRICT]=$m[E_DEPRECATED]=$m[E_USER_DEPRECATED]=$m[E_ALL]=LogLevel::DEBUG; |
|
192 | + $m[2048]=$m[8192]=$m[16384]=$m[32767]=LogLevel::DEBUG; |
|
193 | 193 | |
194 | 194 | if (isset($m[$level])) { |
195 | 195 | return $m[$level]; |
196 | 196 | } |
197 | 197 | |
198 | - throw new \Exception(__FUNCTION__ . "($level): $level is unknown"); |
|
198 | + throw new \Exception(__FUNCTION__."($level): $level is unknown"); |
|
199 | 199 | } |
200 | 200 | } |
@@ -72,8 +72,7 @@ |
||
72 | 72 | $this->alert(self::USER_EXCEPTION, [$throwable]); |
73 | 73 | } elseif ($throwable instanceof \Error) { |
74 | 74 | $this->notice(self::INTERNAL_ERROR, [$throwable]); |
75 | - } |
|
76 | - else { |
|
75 | + } else { |
|
77 | 76 | $this->critical('Caught an unknown Throwable. This breaks everything.', [$throwable]); |
78 | 77 | } |
79 | 78 | } |