Last active
February 14, 2024 17:47
-
-
Save macintacos/c6f58d2b0ed167b71466b20ec3fed7e7 to your computer and use it in GitHub Desktop.
JSON file for formatting `lnav` MongoDB logs, both "pre" 4.4 and "post" 4.4 (i.e. when structured logging was introduced). Place these files in `$HOME/.lnav/formats/installed`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"mongod_post44": { | |
"title": "MongoDB 4.4 Log format", | |
"description": "New log format beginning with MongoDB 4.4", | |
"url": "https://docs.mongodb.com/manual/reference/log-messages/index.html#structured-logging", | |
"json": true, | |
"file-pattern": ".*mongodb.log", | |
"line-format": [ | |
{ "field": "__timestamp__" }, | |
" ", | |
{ "field": "s", "min-width": 1, "align": "left" }, | |
" ", | |
{ "field": "c", "min-width": 8, "align": "left" }, | |
" [", | |
{ | |
"field": "ctx", | |
"max-width": 20, | |
"overflow": "truncate", | |
"align": "left" | |
}, | |
"] id:", | |
{ | |
"field": "id" | |
}, | |
" (", | |
{ | |
"field": "attr/remote", | |
"max-width": 22, | |
"align": "left" | |
}, | |
") ", | |
{ "field": "msg" }, | |
" ", | |
{ "field": "attr" }, | |
" ", | |
{ "field": "tags", "default-value": "" }, | |
" ", | |
{ "field": "truncated", "default-value": "" }, | |
" ", | |
{ "field": "size", "default-value": "" } | |
], | |
"timestamp-field": "t/$date", | |
"level-field": "s", | |
"body-field": "msg", | |
"opid-field": "ctx", | |
"level": { | |
"fatal": "F", | |
"error": "E", | |
"warning": "W", | |
"info": "I", | |
"debug": "D1", | |
"debug2": "D2", | |
"debug3": "D3", | |
"debug4": "D4", | |
"debug5": "D5" | |
}, | |
"value": { | |
"t": { "kind": "json", "hidden": true }, | |
"t/$date": { "kind": "string" }, | |
"s": { "kind": "string" }, | |
"c": { "kind": "string", "identifier": true }, | |
"id": { "kind": "integer", "identifier": true, "hidden": true }, | |
"ctx": { | |
"kind": "string", | |
"identifier": true | |
}, | |
"tags": { "kind": "json", "hidden": true }, | |
"msg": { "kind": "string" }, | |
"attr": { "kind": "json" }, | |
"attr/remote": { | |
"kind": "string", | |
"collate": "ipaddress", | |
"identifier": true | |
}, | |
"truncated": { "kind": "json" }, | |
"size": { "kind": "integer" } | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"mongod_pre44": { | |
"title": "MongoDB server log format", | |
"regex": { | |
"main": { | |
"pattern": "^(?<timestamp>\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}[,\\.]\\d+\\+\\d+)\\s+(?<level>\\w)\\s+(?<component>\\w+|-)\\s+\\[?(?<context>-*[^\\0]+?)?\\]\\s+(?<body>[^\\0]*)$" | |
} | |
}, | |
"level": { | |
"critical": "F", | |
"debug": "D", | |
"error": "E", | |
"info": "I", | |
"warning": "W" | |
}, | |
"opid-field": "context", | |
"value": { | |
"context": { | |
"kind": "string", | |
"identifier": true | |
}, | |
"component": { | |
"kind": "string", | |
"identifier": true | |
}, | |
"body": { | |
"kind": "string" | |
} | |
}, | |
"sample": [ | |
{ | |
"line": "2016-11-21T11:55:09.601+0000 I CONTROL [initandlisten] MongoDB starting : pid=19972 port=27017 dbpath=/var/lib/mongodb 32-bit host=ubuntu-512mb-fra1-012" | |
}, | |
{ | |
"line": "2016-12-24T05:05:49.136+0000 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted" | |
}, | |
{ | |
"line": "2019-10-30T17:01:47.736+0000 I INDEX [repl writer worker 0] building index using bulk method build may temporarily use up to 500 megabytes of RAM" | |
} | |
] | |
} | |
} |
There are two formats now, one for pre-4.4 and one for post-4.4. You should be able to create both of these files and view both types of logs (lnav
is smart enough to figure out which one to use).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Recently updated such that it should now properly identify "contexts" that have characters other than alphanumeric (such as spaces or dashes, which show up during index builds and some networking operations)