diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Format.php | 8 | ||||
| -rw-r--r-- | src/Loggr.php | 12 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/Format.php b/src/Format.php index 4517e0a..fa1c215 100644 --- a/src/Format.php +++ b/src/Format.php @@ -43,7 +43,7 @@ enum Format /** @var string $trace_line */ $trace_line = $message->trace['line']; - return json_encode([ + $json = json_encode([ 'date' => $dateTime->format('Y-m-d H:i:s'), 'level' => strtoupper($message->level->value), 'message' => $message->content, @@ -53,6 +53,12 @@ enum Format 'line' => $trace_line, ], ]); + + if (!$json) { + return ''; + } + + return $json; } /** diff --git a/src/Loggr.php b/src/Loggr.php index 78b3504..82d5681 100644 --- a/src/Loggr.php +++ b/src/Loggr.php @@ -159,8 +159,18 @@ class Loggr implements LoggerInterface $this->write(Level::Debug, $message, $context); } - public function log(mixed $level, \Stringable|string $message, array $context = []): void + /** + * Logs a message with the specified level and context. + * + * @param mixed $level The logging level (e.g., error, info, debug). + * @param \Stringable|string $message The message to log. + * @param mixed $context Optional context information to include in the log. + * @return void + */ + public function log(mixed $level, \Stringable|string $message, mixed $context = null): void { + if (!is_string($level) && !is_int($level)) return; + $this->trace = debug_backtrace()[0]; $this->write(Level::from($level), $message, $context); } |
