@@ -15,9 +15,9 @@ |
||
15 | 15 | * |
16 | 16 | * @return void |
17 | 17 | */ |
18 | - public function nice($message, array $context = array()); |
|
18 | + public function nice($message, array $context=array()); |
|
19 | 19 | |
20 | - public function reportToUser($level, $message, $context = []); |
|
20 | + public function reportToUser($level, $message, $context=[]); |
|
21 | 21 | public function getUserReport(); |
22 | 22 | public function cleanUserReport(); |
23 | 23 |
@@ -172,7 +172,7 @@ |
||
172 | 172 | * const NOTICE = 'notice'; // Normal but significant events. |
173 | 173 | * const INFO = 'info'; // Interesting events. User logs in, SQL logs. |
174 | 174 | * const DEBUG = 'debug'; // Detailed debug information. |
175 | - */ |
|
175 | + */ |
|
176 | 176 | private static function mapErrorLevelToLogLevel($level): string |
177 | 177 | { |
178 | 178 | // http://php.net/manual/en/errorfunc.constants.php |
@@ -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 $hasHaltingMessages = false; |
|
27 | + private $hasHaltingMessages=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 errorHandler($level, $message, $file = '', $line = 0) |
|
59 | + public function errorHandler($level, $message, $file='', $line=0) |
|
60 | 60 | { |
61 | - $loglevel = self::mapErrorLevelToLogLevel($level); |
|
61 | + $loglevel=self::mapErrorLevelToLogLevel($level); |
|
62 | 62 | $this->$loglevel($message, ['file' => $file, 'line' => $line, 'trace' => debug_backtrace()]); |
63 | 63 | } |
64 | 64 | |
@@ -91,22 +91,22 @@ discard block |
||
91 | 91 | |
92 | 92 | // -- Implementation of LoggerInterface::log(), all other methods are in LoggerTrait |
93 | 93 | |
94 | - public function log($level, $message, array $context = []) |
|
94 | + public function log($level, $message, array $context=[]) |
|
95 | 95 | { |
96 | - $display_error = null; |
|
96 | + $display_error=null; |
|
97 | 97 | |
98 | 98 | // --- Handles Throwables (exception_handler()) |
99 | 99 | if ($message === self::INTERNAL_ERROR || $message === self::USER_EXCEPTION) { |
100 | - $this->hasHaltingMessages = true; |
|
101 | - if (($context = current($context)) !== false) { |
|
102 | - $display_error = Debugger::formatThrowable($context); |
|
103 | - $display_error .= PHP_EOL . Debugger::tracesToString($context->getTrace(), false); |
|
100 | + $this->hasHaltingMessages=true; |
|
101 | + if (($context=current($context)) !== false) { |
|
102 | + $display_error=Debugger::formatThrowable($context); |
|
103 | + $display_error.=PHP_EOL.Debugger::tracesToString($context->getTrace(), false); |
|
104 | 104 | error_log($display_error); |
105 | 105 | self::HTTP500($display_error); |
106 | 106 | } |
107 | 107 | } elseif ($this->systemHalted($level)) { // analyses error level |
108 | - $display_error = sprintf( |
|
109 | - PHP_EOL . '%s in file %s:%d' . PHP_EOL . '%s', |
|
108 | + $display_error=sprintf( |
|
109 | + PHP_EOL.'%s in file %s:%d'.PHP_EOL.'%s', |
|
110 | 110 | $level, |
111 | 111 | Debugger::formatFilename($context['file']), |
112 | 112 | $context['line'], |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | |
116 | 116 | error_log($display_error); |
117 | 117 | |
118 | - $display_error .= PHP_EOL . Debugger::tracesToString($context['trace'], true); |
|
118 | + $display_error.=PHP_EOL.Debugger::tracesToString($context['trace'], true); |
|
119 | 119 | self::HTTP500($display_error); |
120 | 120 | } else {// --- Handles user messages, through SESSION storage |
121 | 121 | $this->reportToUser($level, $message, $context); |
@@ -137,17 +137,17 @@ discard block |
||
137 | 137 | // -- User messages |
138 | 138 | |
139 | 139 | // -- User messages:add one |
140 | - public function reportToUser($level, $message, $context = []) |
|
140 | + public function reportToUser($level, $message, $context=[]) |
|
141 | 141 | { |
142 | 142 | if (!isset($_SESSION[self::REPORTING_USER])) { |
143 | - $_SESSION[self::REPORTING_USER] = []; |
|
143 | + $_SESSION[self::REPORTING_USER]=[]; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | if (!isset($_SESSION[self::REPORTING_USER][$level])) { |
147 | - $_SESSION[self::REPORTING_USER][$level] = []; |
|
147 | + $_SESSION[self::REPORTING_USER][$level]=[]; |
|
148 | 148 | } |
149 | 149 | |
150 | - $_SESSION[self::REPORTING_USER][$level][] = [$message, $context]; |
|
150 | + $_SESSION[self::REPORTING_USER][$level][]=[$message, $context]; |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // -- User messages:get all |
@@ -176,24 +176,24 @@ discard block |
||
176 | 176 | private static function mapErrorLevelToLogLevel($level): string |
177 | 177 | { |
178 | 178 | // http://php.net/manual/en/errorfunc.constants.php |
179 | - $m = []; |
|
179 | + $m=[]; |
|
180 | 180 | |
181 | - $m[E_ERROR] = $m[E_PARSE] = $m[E_CORE_ERROR] = $m[E_COMPILE_ERROR] = $m[E_USER_ERROR] = $m[E_RECOVERABLE_ERROR] = LogLevel::ALERT; |
|
182 | - $m[1] = $m[4] = $m[16] = $m[64] = $m[256] = $m[4096] = LogLevel::ALERT; |
|
181 | + $m[E_ERROR]=$m[E_PARSE]=$m[E_CORE_ERROR]=$m[E_COMPILE_ERROR]=$m[E_USER_ERROR]=$m[E_RECOVERABLE_ERROR]=LogLevel::ALERT; |
|
182 | + $m[1]=$m[4]=$m[16]=$m[64]=$m[256]=$m[4096]=LogLevel::ALERT; |
|
183 | 183 | |
184 | - $m[E_WARNING] = $m[E_CORE_WARNING] = $m[E_COMPILE_WARNING] = $m[E_USER_WARNING] = LogLevel::CRITICAL; |
|
185 | - $m[2] = $m[32] = $m[128] = $m[512] = LogLevel::CRITICAL; |
|
184 | + $m[E_WARNING]=$m[E_CORE_WARNING]=$m[E_COMPILE_WARNING]=$m[E_USER_WARNING]=LogLevel::CRITICAL; |
|
185 | + $m[2]=$m[32]=$m[128]=$m[512]=LogLevel::CRITICAL; |
|
186 | 186 | |
187 | - $m[E_NOTICE] = $m[E_USER_NOTICE] = LogLevel::ERROR; |
|
188 | - $m[8] = $m[1024] = LogLevel::ERROR; |
|
187 | + $m[E_NOTICE]=$m[E_USER_NOTICE]=LogLevel::ERROR; |
|
188 | + $m[8]=$m[1024]=LogLevel::ERROR; |
|
189 | 189 | |
190 | - $m[E_STRICT] = $m[E_DEPRECATED] = $m[E_USER_DEPRECATED] = $m[E_ALL] = LogLevel::DEBUG; |
|
191 | - $m[2048] = $m[8192] = $m[16384] = $m[32767] = LogLevel::DEBUG; |
|
190 | + $m[E_STRICT]=$m[E_DEPRECATED]=$m[E_USER_DEPRECATED]=$m[E_ALL]=LogLevel::DEBUG; |
|
191 | + $m[2048]=$m[8192]=$m[16384]=$m[32767]=LogLevel::DEBUG; |
|
192 | 192 | |
193 | 193 | if (isset($m[$level])) { |
194 | 194 | return $m[$level]; |
195 | 195 | } |
196 | 196 | |
197 | - throw new \Exception(__FUNCTION__ . "($level): $level is unknown"); |
|
197 | + throw new \Exception(__FUNCTION__."($level): $level is unknown"); |
|
198 | 198 | } |
199 | 199 | } |