@@ -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 |
@@ -20,18 +20,18 @@ discard block |
||
20 | 20 | class LogLaddy extends \Psr\Log\AbstractLogger |
21 | 21 | { |
22 | 22 | // public const REPORTING_USER = 'user_messages'; |
23 | - public const INTERNAL_ERROR = 'error'; |
|
24 | - public const USER_EXCEPTION = 'exception'; |
|
23 | + public const INTERNAL_ERROR='error'; |
|
24 | + public const USER_EXCEPTION='exception'; |
|
25 | 25 | // public const LOG_LEVEL_SUCCESS = 'ok'; |
26 | 26 | |
27 | - private $hasHaltingMessages = false; |
|
27 | + private $hasHaltingMessages=false; |
|
28 | 28 | |
29 | - private $state_agent = null; |
|
29 | + private $state_agent=null; |
|
30 | 30 | |
31 | 31 | |
32 | 32 | public function __construct(StateAgentInterface $agent) |
33 | 33 | { |
34 | - $this->state_agent = $agent; |
|
34 | + $this->state_agent=$agent; |
|
35 | 35 | $this->setHandlers(); |
36 | 36 | } |
37 | 37 | |
@@ -51,9 +51,9 @@ discard block |
||
51 | 51 | * handler for errors |
52 | 52 | * use set_error_handler('\HexMakina\kadro\Logger\LogLaddy::error_handler') |
53 | 53 | */ |
54 | - public function errorHandler($level, $message, $file = '', $line = 0) |
|
54 | + public function errorHandler($level, $message, $file='', $line=0) |
|
55 | 55 | { |
56 | - $loglevel = self::mapErrorLevelToLogLevel($level); |
|
56 | + $loglevel=self::mapErrorLevelToLogLevel($level); |
|
57 | 57 | $this->$loglevel($message, ['file' => $file, 'line' => $line, 'trace' => debug_backtrace()]); |
58 | 58 | } |
59 | 59 | |
@@ -86,22 +86,22 @@ discard block |
||
86 | 86 | |
87 | 87 | // -- Implementation of LoggerInterface::log(), all other methods are in LoggerTrait |
88 | 88 | |
89 | - public function log($level, $message, array $context = []) |
|
89 | + public function log($level, $message, array $context=[]) |
|
90 | 90 | { |
91 | - $display_error = null; |
|
91 | + $display_error=null; |
|
92 | 92 | |
93 | 93 | // --- Handles Throwables (exception_handler()) |
94 | 94 | if ($message === self::INTERNAL_ERROR || $message === self::USER_EXCEPTION) { |
95 | - $this->hasHaltingMessages = true; |
|
96 | - if (($context = current($context)) !== false) { |
|
97 | - $display_error = Debugger::formatThrowable($context); |
|
98 | - $display_error .= PHP_EOL . Debugger::tracesToString($context->getTrace(), false); |
|
95 | + $this->hasHaltingMessages=true; |
|
96 | + if (($context=current($context)) !== false) { |
|
97 | + $display_error=Debugger::formatThrowable($context); |
|
98 | + $display_error.=PHP_EOL.Debugger::tracesToString($context->getTrace(), false); |
|
99 | 99 | error_log($display_error); |
100 | 100 | self::HTTP500($display_error); |
101 | 101 | } |
102 | 102 | } elseif ($this->systemHalted($level)) { // analyses error level |
103 | - $display_error = sprintf( |
|
104 | - PHP_EOL . '%s in file %s:%d' . PHP_EOL . '%s', |
|
103 | + $display_error=sprintf( |
|
104 | + PHP_EOL.'%s in file %s:%d'.PHP_EOL.'%s', |
|
105 | 105 | $level, |
106 | 106 | Debugger::formatFilename($context['file']), |
107 | 107 | $context['line'], |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | |
111 | 111 | error_log($display_error); |
112 | 112 | |
113 | - $display_error .= PHP_EOL . Debugger::tracesToString($context['trace'], true); |
|
113 | + $display_error.=PHP_EOL.Debugger::tracesToString($context['trace'], true); |
|
114 | 114 | self::HTTP500($display_error); |
115 | 115 | } else {// --- Handles user messages, through SESSION storage |
116 | 116 | $this->state_agent->addMessage($level, $message, $context); |
@@ -146,24 +146,24 @@ discard block |
||
146 | 146 | private static function mapErrorLevelToLogLevel($level): string |
147 | 147 | { |
148 | 148 | // http://php.net/manual/en/errorfunc.constants.php |
149 | - $m = []; |
|
149 | + $m=[]; |
|
150 | 150 | |
151 | - $m[E_ERROR] = $m[E_PARSE] = $m[E_CORE_ERROR] = $m[E_COMPILE_ERROR] = $m[E_USER_ERROR] = $m[E_RECOVERABLE_ERROR] = LogLevel::ALERT; |
|
152 | - $m[1] = $m[4] = $m[16] = $m[64] = $m[256] = $m[4096] = LogLevel::ALERT; |
|
151 | + $m[E_ERROR]=$m[E_PARSE]=$m[E_CORE_ERROR]=$m[E_COMPILE_ERROR]=$m[E_USER_ERROR]=$m[E_RECOVERABLE_ERROR]=LogLevel::ALERT; |
|
152 | + $m[1]=$m[4]=$m[16]=$m[64]=$m[256]=$m[4096]=LogLevel::ALERT; |
|
153 | 153 | |
154 | - $m[E_WARNING] = $m[E_CORE_WARNING] = $m[E_COMPILE_WARNING] = $m[E_USER_WARNING] = LogLevel::CRITICAL; |
|
155 | - $m[2] = $m[32] = $m[128] = $m[512] = LogLevel::CRITICAL; |
|
154 | + $m[E_WARNING]=$m[E_CORE_WARNING]=$m[E_COMPILE_WARNING]=$m[E_USER_WARNING]=LogLevel::CRITICAL; |
|
155 | + $m[2]=$m[32]=$m[128]=$m[512]=LogLevel::CRITICAL; |
|
156 | 156 | |
157 | - $m[E_NOTICE] = $m[E_USER_NOTICE] = LogLevel::ERROR; |
|
158 | - $m[8] = $m[1024] = LogLevel::ERROR; |
|
157 | + $m[E_NOTICE]=$m[E_USER_NOTICE]=LogLevel::ERROR; |
|
158 | + $m[8]=$m[1024]=LogLevel::ERROR; |
|
159 | 159 | |
160 | - $m[E_STRICT] = $m[E_DEPRECATED] = $m[E_USER_DEPRECATED] = $m[E_ALL] = LogLevel::DEBUG; |
|
161 | - $m[2048] = $m[8192] = $m[16384] = $m[32767] = LogLevel::DEBUG; |
|
160 | + $m[E_STRICT]=$m[E_DEPRECATED]=$m[E_USER_DEPRECATED]=$m[E_ALL]=LogLevel::DEBUG; |
|
161 | + $m[2048]=$m[8192]=$m[16384]=$m[32767]=LogLevel::DEBUG; |
|
162 | 162 | |
163 | 163 | if (isset($m[$level])) { |
164 | 164 | return $m[$level]; |
165 | 165 | } |
166 | 166 | |
167 | - throw new \Exception(__FUNCTION__ . "($level): $level is unknown"); |
|
167 | + throw new \Exception(__FUNCTION__."($level): $level is unknown"); |
|
168 | 168 | } |
169 | 169 | } |