Skip to content

Instantly share code, notes, and snippets.

@lamchau
Last active February 29, 2024 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lamchau/bb12fc5265c77e275905b382ae3e425d to your computer and use it in GitHub Desktop.
Save lamchau/bb12fc5265c77e275905b382ae3e425d to your computer and use it in GitHub Desktop.
lnav.org logging definition for https://github.com/tbd54566975/ftl

Usage

For usage with lnav allowing for consolidated/colored logs with FTL

Installation

curl \
  --silent \
  --output $XDG_CONFIG_HOME/lnav/formats/installed/ftl_json.json \
  "https://gist.githubusercontent.com/lamchau/bb12fc5265c77e275905b382ae3e425d/raw/d9288304a80b50ca0f65cbbeeec5cc060401b01a/ftl_json.json"`

Running FTL with lnav

tl;dr - Assumes ftl-.*.log.json as the file-pattern (e.g. ftl-foo.log.json)

Why? lnav can parse JSON files natively but because it'd be challenging to figure out across multiple JSON structs so we give it a filename to help it identify the format.

ftl dev . \
  --log-level=debug \
  --log-json 2>&1 |
  tee -a "logs/ftl-$(date +'%F').log.json"
ftl serve \
  --log-level=debug \
  --log-json 2>&1 |
  tee -a "logs/ftl-$(date +'%F').log.json"
{
"$schema": "https://lnav.org/schemas/format-v1.schema.json",
"ftl_json": {
"title": "FTL JSON log format",
"description": "FTL JSON log format",
"timestamp-field": "time",
"json": true,
"file-pattern": "ftl-.*\\.log\\.json",
"level-field": "level",
"level": {
"debug": "debug",
"info": "info",
"warning": "warn",
"error": "error",
"fatal": "fatal"
},
"body-field": "message",
"value": {
"message": {
"identifier": false,
"kind": "string"
},
"attributes": {
"identifier": true,
"kind": "json"
}
},
"highlights": {
"fatal": {
"color": "Red1",
"pattern": "CRITICAL|FATAL|fatal"
},
"error": {
"color": "OrangeRed1",
"pattern": "ERROR"
},
"warning": {
"color": "Orange1",
"pattern": "WARN"
},
"info": {
"color": "Blue1",
"pattern": "INFO"
},
"debug": {
"color": "Grey62",
"pattern": "DEBUG"
}
},
"line-format": [
{
"field": "__timestamp__",
"timestamp-format": "%Y-%m-%dT%H:%M:%S.%N%Z"
},
" ",
{
"field": "level",
"text-transform": "uppercase",
"auto-width": true,
"min-width": 7,
"align": "right",
"prefix": "[",
"suffix": "]"
},
" ",
{
"field": "message"
}
],
"sample": [
{"level":"info","message":"Starting FTL with 1 controller(s) and 0 runner(s)","time":"2024-02-20T15:17:11.995118-08:00"},
{"level":"debug","message":"Reusing existing docker container \"ftl-db-1\" on port \"54320\" for postgres db","time":"2024-02-20T15:17:12.180235-08:00"},
{"level":"debug","message":"Waiting for ftl-db-1 to be healthy","time":"2024-02-20T15:17:12.180279-08:00"},
{"level":"debug","message":"Postgres DSN: postgres://postgres:secret@localhost:54320/ftl?sslmode=disable","time":"2024-02-20T15:17:12.231408-08:00"},
{"level":"debug","attributes":{"runner":"R00000000000000000000002000","scope":"runner0"},"message":"Starting FTL Runner","time":"2024-02-21T00:10:02.83817-08:00"},
{"level":"debug","attributes":{"runner":"R00000000000000000000002000","scope":"runner0"},"message":"Deployment directory: /Users/quokka/Library/Caches/ftl-runner/runner0/deployments","time":"2024-02-21T00:10:02.838174-08:00"}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment