Skip to content

Instantly share code, notes, and snippets.

@nickpeirson
Forked from skowron-line/monolog.json
Last active February 29, 2024 09:58
Show Gist options
  • Save nickpeirson/6ea39176d0a6efbf77018c05bdaa9ba1 to your computer and use it in GitHub Desktop.
Save nickpeirson/6ea39176d0a6efbf77018c05bdaa9ba1 to your computer and use it in GitHub Desktop.
lnav Monolog format
{
"monolog": {
"title": "Monolog log file",
"description": "Monolog log format",
"url": "https://github.com/Seldaek/monolog",
"regex": {
"default": {
"pattern": "\\[(?P<timestamp>.*)\\] (?P<logger>\\w+).(?P<level>\\w+): (?P<message>.+) (?P<context>[\\[\\{].*[\\]\\}]) (?P<extra>[\\[\\{].*[\\]\\}])$"
}
},
"level-field" : "level",
"body-field" : "message",
"level": {
"fatal": "EMERGENCY",
"critical": "ALERT|CRITICAL",
"error": "ERROR",
"warning": "WARNING",
"stats": "NOTICE",
"info": "INFO",
"debug": "DEBUG"
},
"value": {
"logger": {
"kind": "string",
"identifier": true
},
"level": {
"kind": "string",
"identifier": true
},
"message": {
"kind": "string"
},
"context": {
"kind": "json"
},
"extra": {
"kind": "json"
}
},
"sample": [
{
"line": "[2015-08-10 15:05:12] event.DEBUG: Notified event \"kernel.terminate\" to listener \"Symfony\\Component\\HttpKernel\\EventListener\\ProfilerListener::onKernelTerminate\". [] []"
}
]
}
}
@nickpeirson
Copy link
Author

Expanded log level map (thanks @Everis) and correctly set the body-field so highlighting is applied to quoted strings, IPs, etc, in the message.

@nickpeirson
Copy link
Author

Still room for improvement, it doesn't handle the following log line due to the square brackets:
[2016-10-07 10:03:12] app.ERROR: Not set $foo['bar'] [] []

I suspect the fix is to anchor the regex to the end of the line and work backwards to find the two preceding fields, allowing the message capture group to pick up everything not assigned to another field.

@nickpeirson
Copy link
Author

Updated. Seems to work for my current logs.

@Charl13
Copy link

Charl13 commented Aug 11, 2020

Thanks @nickpeirson, works great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment