[GH-ISSUE #1495] JsonFormatter fails sometimes #631

Closed
opened 2026-03-04 02:16:33 +03:00 by kerem · 1 comment
Owner

Originally created by @curtiscarlson on GitHub (Sep 2, 2020).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1495

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...

Originally created by @curtiscarlson on GitHub (Sep 2, 2020). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1495 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...
kerem 2026-03-04 02:16:33 +03:00
  • closed this issue
  • added the
    Bug
    label
Author
Owner

@Seldaek commented on GitHub (Dec 11, 2020):

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

<!-- gh-comment-id:743075432 --> @Seldaek commented on GitHub (Dec 11, 2020): Monolog 2 has much better handling for this, I'd recommend upgrading if you can.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#631
No description provided.