Lines
95.74%
45 / 47
Methods
86.66%
13 / 15
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| log | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Lucent\Logging\Channel] getName | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| [Lucent\Logging\Channel] highlightLine | 83.33% | 5 / 6 | 0.00% | 0 / 1 | 4.07 | ||
| [Lucent\Logging\Channel] formatMessage | 100.00% | 20 / 20 | 100.00% | 1 / 1 | 2 | ||
| [Lucent\Logging\Channel] write | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Lucent\Logging\Channel] interpolate | 100.00% | 9 / 9 | 100.00% | 1 / 1 | 7 | ||
| [Lucent\Logging\Channel] emergency | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Lucent\Logging\Channel] alert | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Lucent\Logging\Channel] critical | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Lucent\Logging\Channel] error | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Lucent\Logging\Channel] warning | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Lucent\Logging\Channel] notice | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Lucent\Logging\Channel] info | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Lucent\Logging\Channel] debug | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| 18 | class NullChannel extends Channel | |
| 19 | { | |
| 20 | public function __construct() | |
| 21 | { | |
| 22 | parent::__construct('null', new NullDriver()); | |
| 23 | } | |
| 24 | ||
| 25 | public function log($level, string|\Stringable $message, array $context = []): void | |
| 26 | { | |
| 27 | // Intentionally empty — true no-op per PSR-3 NullLogger convention. | |
| 28 | } | |
| 29 | } |
Inherited from Lucent\Logging\Channel
| 67 | public function getName(): string | |
| 68 | { | |
| 69 | return $this->channel; | |
| 70 | } |
| 72 | private function highlightLine(string $line): string | |
| 73 | { | |
| 74 | foreach ($this->highlighters as $highlighter) { | |
| 75 | if (!($highlighter instanceof Highlighter)) { | |
| 76 | continue; | |
| 77 | } | |
| 78 | ||
| 79 | if ($highlighter->shouldHighlight($line, $line)) { | |
| 80 | $line = $highlighter->highlight($line, $line); | |
| 81 | } | |
| 82 | } | |
| 83 | ||
| 84 | return $line; | |
| 85 | } |
| 87 | private function formatMessage(string $level, string $message): string | |
| 88 | { | |
| 89 | $timestamp = date('Y-m-d H:i:s'); | |
| 90 | $levelUpper = strtoupper($level); | |
| 91 | ||
| 92 | if ($this->useColors) { | |
| 93 | $levelColor = $this->levelColors[$level] ?? "\033[0m"; | |
| 94 | $formattedMessage = $this->highlightLine($message); | |
| 95 | return sprintf( | |
| 96 | "[%s] %s%s\033[0m | %s | %s\n", | |
| 97 | $timestamp, | |
| 98 | $levelColor, | |
| 99 | $levelUpper, | |
| 100 | $this->channel, | |
| 101 | $formattedMessage | |
| 102 | ); | |
| 103 | } | |
| 104 | ||
| 105 | return sprintf( | |
| 106 | "[%s] %s | %s | %s\n", | |
| 107 | $timestamp, | |
| 108 | $levelUpper, | |
| 109 | $this->channel, | |
| 110 | $message | |
| 111 | ); | |
| 112 | } |
| 114 | private function write(string $level, string $message): void | |
| 115 | { | |
| 116 | $this->driver->write($this->formatMessage($level, $message)); | |
| 117 | } |
| 127 | private function interpolate(string|\Stringable $message, array $context): string | |
| 128 | { | |
| 129 | if ($context === []) { | |
| 130 | return (string) $message; | |
| 131 | } | |
| 132 | ||
| 133 | $replace = []; | |
| 134 | foreach ($context as $key => $value) { | |
| 135 | if ($key === 'exception') { | |
| 136 | continue; | |
| 137 | } | |
| 138 | ||
| 139 | if (is_string($value) || is_scalar($value) || $value instanceof \Stringable) { | |
| 140 | $replace['{' . $key . '}'] = (string) $value; | |
| 141 | } | |
| 142 | } | |
| 143 | ||
| 144 | return strtr((string) $message, $replace); | |
| 145 | } |
| 169 | public function emergency(string|\Stringable $message, array $context = []): void | |
| 170 | { | |
| 171 | $this->log(LogLevel::EMERGENCY, $message, $context); | |
| 172 | } |
| 174 | public function alert(string|\Stringable $message, array $context = []): void | |
| 175 | { | |
| 176 | $this->log(LogLevel::ALERT, $message, $context); | |
| 177 | } |
| 179 | public function critical(string|\Stringable $message, array $context = []): void | |
| 180 | { | |
| 181 | $this->log(LogLevel::CRITICAL, $message, $context); | |
| 182 | } |
| 184 | public function error(string|\Stringable $message, array $context = []): void | |
| 185 | { | |
| 186 | $this->log(LogLevel::ERROR, $message, $context); | |
| 187 | } |
| 189 | public function warning(string|\Stringable $message, array $context = []): void | |
| 190 | { | |
| 191 | $this->log(LogLevel::WARNING, $message, $context); | |
| 192 | } |
| 194 | public function notice(string|\Stringable $message, array $context = []): void | |
| 195 | { | |
| 196 | $this->log(LogLevel::NOTICE, $message, $context); | |
| 197 | } |
| 199 | public function info(string|\Stringable $message, array $context = []): void | |
| 200 | { | |
| 201 | $this->log(LogLevel::INFO, $message, $context); | |
| 202 | } |
| 204 | public function debug(string|\Stringable $message, array $context = []): void | |
| 205 | { | |
| 206 | $this->log(LogLevel::DEBUG, $message, $context); | |
| 207 | } |