[GH-ISSUE #110] IntrospectionProcessor and LineFormatter invalid JSON #38

Closed
opened 2026-03-04 02:11:35 +03:00 by kerem · 6 comments
Owner

Originally created by @jrjohnson on GitHub (Sep 5, 2012).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/110

The introspection processor adds the class name to the extra paramters - if this name is namespaced (has a ) then the json that results from LineFormatter is invalid and cannot be re-assembled using json_decode.

eg:

{
    "file": "/src/Name/NameClass.php",
    "class": "Name\NameClass"
}

Its possible this is addressed in PHP 5.4 using the JSON_UNESCAPED_SLASHES - but it should be backwards compatible as well. I assume this would be an issue for any unescape slashes added by any of the processors.

Originally created by @jrjohnson on GitHub (Sep 5, 2012). Original GitHub issue: https://github.com/Seldaek/monolog/issues/110 The introspection processor adds the class name to the extra paramters - if this name is namespaced (has a ) then the json that results from LineFormatter is invalid and cannot be re-assembled using json_decode. eg: ``` javascript { "file": "/src/Name/NameClass.php", "class": "Name\NameClass" } ``` Its possible this is addressed in PHP 5.4 using the JSON_UNESCAPED_SLASHES - but it should be backwards compatible as well. I assume this would be an issue for any unescape slashes added by any of the processors.
kerem closed this issue 2026-03-04 02:11:35 +03:00
Author
Owner

@stof commented on GitHub (Sep 5, 2012):

Please fix your markdown to use code-blocks when necessary, to avoid the escaping of the content. The link to the markdown help is available both in the footer of the github website and near the comment form

<!-- gh-comment-id:8306299 --> @stof commented on GitHub (Sep 5, 2012): Please fix your markdown to use code-blocks when necessary, to avoid the escaping of the content. The link to the markdown help is available both in the footer of the github website and near the comment form
Author
Owner

@stof commented on GitHub (Sep 5, 2012):

and btw, in which place does it create invalid json ? LineFormatter is not meant to produce json (there is a JsonFormatter for that)

<!-- gh-comment-id:8306381 --> @stof commented on GitHub (Sep 5, 2012): and btw, in which place does it create invalid json ? LineFormatter is not meant to produce json (there is a JsonFormatter for that)
Author
Owner

@jrjohnson commented on GitHub (Sep 5, 2012):

LineFormater produces JSON in convertToString which gets called in format for every value in extras. It looks to me like the written output of extras is intended to be JSON.

<!-- gh-comment-id:8306568 --> @jrjohnson commented on GitHub (Sep 5, 2012): LineFormater produces JSON in convertToString which gets called in format for every value in extras. It looks to me like the written output of extras is intended to be JSON.
Author
Owner

@stof commented on GitHub (Sep 5, 2012):

@jrjohnson it uses json_encode in some cases (note that it is not all cases), because it is a readable way to write arrays on 1 line. But it was never intended to write json. If you want to log as JSON, use the dedicated formatter

<!-- gh-comment-id:8306631 --> @stof commented on GitHub (Sep 5, 2012): @jrjohnson it uses json_encode in some cases (note that it is not all cases), because it is a readable way to write arrays on 1 line. But it was never intended to write json. If you want to log as JSON, use the dedicated formatter
Author
Owner

@jrjohnson commented on GitHub (Sep 5, 2012):

OK so the extras string is just a comma separated list of values inclosed in {} that is very nearly correct JSON?

{"line":432,"function":"handleException","ip":"206.211.148.90","http_method":"GET","referrer":"NULL"}

<!-- gh-comment-id:8306712 --> @jrjohnson commented on GitHub (Sep 5, 2012): OK so the extras string is just a comma separated list of values inclosed in {} that is very nearly correct JSON? `{"line":432,"function":"handleException","ip":"206.211.148.90","http_method":"GET","referrer":"NULL"}`
Author
Owner

@Seldaek commented on GitHub (Sep 5, 2012):

Indeed in 5.4 it will return proper json, but in 5.3 it didn't because of the slightly too greedy stripslashes. Fixed now.

<!-- gh-comment-id:8311061 --> @Seldaek commented on GitHub (Sep 5, 2012): Indeed in 5.4 it will return proper json, but in 5.3 it didn't because of the slightly too greedy stripslashes. Fixed now.
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#38
No description provided.