yoeriboven / laravel-log-db

A database driver for logging with Laravel
MIT License
45 stars 13 forks source link

Undefined array key "formatted" #18

Closed DiGiTransf closed 8 months ago

DiGiTransf commented 8 months ago

Hi, when I try to log exceptions with your lib, I got a new exception thrown here:

(file): /vendor/yoeriboven/laravel-log-db/src/DatabaseHandler.php ... (line 38): Log::stack($fallbackChannels)->debug($record['formatted']); ...

dd'ed Excepiton is: ErrorException {#2362 ▼ // app/Exceptions/Handler.php:47

message: "Undefined array key "formatted""

code: 0

file: "/umfs/APP/UTILE/affaen66/vendor/yoeriboven/laravel-log-db/src/DatabaseHandler.php"

line: 38

severity: E_WARNING

trace: {▼ /umfs/APP/UTILE/affaen66/vendor/yoeriboven/laravel-log-db/src/DatabaseHandler.php:38 {▼ Illuminate\Foundation\Bootstrap\HandleExceptions->handleError($level, $message, $file = '', $line = 0) … › › Log::stack($fallbackChannels)->debug($record['formatted']); › } ...

Scenario: I have a Oracle 11g database instance running under Laravel 10 application. Timestamps type fields cannot hold Monolog\DateTimeImmutable values (even with TIMESTAMP WITH TIME ZONE type) so writing to LOG_MESSAGE table raise an exception in datetime conversion holding ("invalid month"). But that exception is trapped into the try/catch and tried to log a new "record" that has no "formatted" property.

So in my single case I fixed by changing "logged_at" field to a VARCHAR(255) type, and thus correctly logging all bugs/errors, but it remains that in case of any failure, the try/catch leads to an unhandled possible happening.

Glad to help you further if needed, or to hear any comments by you/the community.

yoeriboven commented 8 months ago

Apparently the formatted key is not always set.

I fixed it by using message as a fallback in 1.2.2.

Thanks for letting me know!