Monolog LineFormatter parsing config?


Author
Message
sirlogalot
sirlogalot
Junior Member (60 reputation)Junior Member (60 reputation)Junior Member (60 reputation)Junior Member (60 reputation)Junior Member (60 reputation)Junior Member (60 reputation)Junior Member (60 reputation)Junior Member (60 reputation)Junior Member (60 reputation)
Group: Forum Members
Posts: 11, Visits: 29
Hi,
Does anyone have working parser settings for Monolog's default LineFormatter output?  I'm finding the mixed string/JSON output a little tricky to parse.

This is the format LineFormatter uses:
"[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"


Here's examples of the two types of output. In the first line the JSON part is an object, in the second it's an array.
[2023-08-28 17:37:40 MDT] Site.ERROR: Error adding note to entry {"entry_id":41000,"error":"Invalid or empty note"} {"foo":"bar"}
[2023-08-28 17:37:40 MDT] Site.ERROR: Error adding note to entry [] {"foo":"bar"}



LogViewPlus Support
LogViewPlus Support
Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)Supreme Being (5.3K reputation)
Group: Moderators
Posts: 1.1K, Visits: 3.7K
This is a tricky file to parse because the message, context and 'extra' are all separated by a single space.  This does not sufficiently delineate where one field stops and another begins.

The LogViewPlus default parser is pretty good in this case which just treats all three fields as a message.  Messages can then be parsed separately where needed, so this isn't a bad option.
[%d{yyyy-MM-dd %H:mm:ss ZZZ}] %c.%p: %m%n

You could also parse out the message and detail by ending the message on the '{' character.  This would treat the context as part of the message.  Something like:
[%d{yyyy-MM-dd %H:mm:ss ZZZ}] %c.%p: %m {%S{Detail}%n

It looks like there is another problem here too.  The 'context' field looks like it may be optional.  LogViewPlus requires all log entries to follow the same schema, so optional fields are not fully supported.  However, there is a work around.  You can parse optional fields by using a multi-pattern and progressing from most to least complicated scenario.  Something like:
[%d{yyyy-MM-dd %H:mm:ss ZZZ}] %c.%p: %m [%S{Context}] %S{Detail}%n
[%d{yyyy-MM-dd %H:mm:ss ZZZ}] %c.%p: %m {%S{Detail}%n
[%d{yyyy-MM-dd %H:mm:ss ZZZ}] %c.%p: %m%n

Adding some context between the [], this would produce a grid like:


Hope that helps,

Toby





sirlogalot
sirlogalot
Junior Member (60 reputation)Junior Member (60 reputation)Junior Member (60 reputation)Junior Member (60 reputation)Junior Member (60 reputation)Junior Member (60 reputation)Junior Member (60 reputation)Junior Member (60 reputation)Junior Member (60 reputation)
Group: Forum Members
Posts: 11, Visits: 29
Thanks!  After trying that, I ended up switching the output of Monolog to use the JsonFormatter instead, much easier to load and parse.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Login

Explore
Messages
Mentions
Search