Seldaek / monolog

Sends your logs to files, sockets, inboxes, databases and various web services

Home Page:https://seldaek.github.io/monolog/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JsonFormatter fails sometimes

curtiscarlson opened this issue · comments

Monolog version 1.24

Log fails to write if json_encode fails. This took a while to figure out. Log file will look like

{"message":"There was an err.....
{"message":"There was an err.....
null 
{"message":"There was an err.....

I went on the console and manually echo $e->getMessage();

There is a SQLSTATE ERROR having to do with bad characters

if I manually echo json_encode($e->getMessage());

it outputs nothing.

This is using use Monolog\Formatter\JsonFormatter

I think it should be updated to store a log with a blank message, at least. The rest of the log could have been intact. This could be a check like if(json_encode($e->getMessage()) === null) $message_body = "error encoding error message"; or something to this effect....

I did find that someone reported this in #616 and it was closed for being corrected, but I am getting this problem still.

The reason it is a problem is that when it just outputs null you dont know when it happened, what file, etc...

Monolog 2 has much better handling for this, I'd recommend upgrading if you can.