Structured Log Formatter
Terminal utility to pretty-print JSON-strucutred log lines.
Usage
slfmt
is intended to be used to filter logging output from a process. It
reads from stdin
and writes to stdout
. It expects to see a JSON object on
each line of input, and will pretty-print the object to stdout
. Escape codes
in the log lines (\n
for newlines, etc.) are supported and will be expanded
in the output.
Any lines that are not valid JSON objects will be printed as-is to stdout
.
Example:
./run-server | slfmt
Sample Output:
---------------------------------------------------------------------------------------
scope: "server/rest_api"
level: "ERROR"
ts:
2025-01-03T08:46:35-06:00 (local) 2025-01-03T14:46:35Z (UTC)
msg: unhandled exception (DbError)
err:
ERROR: relation "users" does not exist
LINE 1: SELECT id FROM users WHERE id = '43422d65-6874-44ce-b9b3-f8c...
^
stack:
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/mummy-0.4.5-cb7f70cd4d6fd3a563e00e664cfbd8cbd3c39b79/mummy.nim(519) workerProc
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/mummy-0.4.5-cb7f70cd4d6fd3a563e00e664cfbd8cbd3c39b79/mummy.nim(450) runTask
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/mummy-0.4.5-cb7f70cd4d6fd3a563e00e664cfbd8cbd3c39b79/mummy/routers.nim(271) :anonymous
/home/username/projects/server/api/src/main/nim/server_api/api.nim(65) :anonymous
/home/username/projects/server/api/src/main/nim/server_api/auth.nim(74) extractSession
/home/username/projects/fiber-orm-nim/src/fiber_orm.nim(599) createOrUpdateUser
/home/username/projects/fiber-orm-nim/src/fiber_orm.nim(384) createOrUpdateRecord
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/db_connector-0.1.0-d68319e3785fa937f0465ea915e942b61b6b5442/db_connector/db_postgres.nim(497) getAllRows
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/db_connector-0.1.0-d68319e3785fa937f0465ea915e942b61b6b5442/db_connector/db_postgres.nim(174) setupQuery
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/db_connector-0.1.0-d68319e3785fa937f0465ea915e942b61b6b5442/db_connector/db_postgres.nim(116) dbError
[[reraised from:
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/mummy-0.4.5-cb7f70cd4d6fd3a563e00e664cfbd8cbd3c39b79/mummy.nim(519) workerProc
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/mummy-0.4.5-cb7f70cd4d6fd3a563e00e664cfbd8cbd3c39b79/mummy.nim(450) runTask
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/mummy-0.4.5-cb7f70cd4d6fd3a563e00e664cfbd8cbd3c39b79/mummy/routers.nim(271) :anonymous
/home/username/projects/server/api/src/main/nim/server_api/api.nim(65) :anonymous
/home/username/projects/server/api/src/main/nim/server_api/auth.nim(74) extractSession
/home/username/projects/fiber-orm-nim/src/fiber_orm.nim(727) createOrUpdateUser
]]
---------------------------------------------------------------------------------------
scope: "server/rest_api"
level: "ERROR"
ts:
2025-01-03T08:46:35-06:00 (local) 2025-01-03T14:46:35Z (UTC)
msg: unhandled exception (DbError)
err:
ERROR: relation "users" does not exist
LINE 1: SELECT id FROM users WHERE id = '43422d65-6874-44ce-b9b3-f8c...
^
stack:
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/mummy-0.4.5-cb7f70cd4d6fd3a563e00e664cfbd8cbd3c39b79/mummy.nim(519) workerProc
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/mummy-0.4.5-cb7f70cd4d6fd3a563e00e664cfbd8cbd3c39b79/mummy.nim(450) runTask
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/mummy-0.4.5-cb7f70cd4d6fd3a563e00e664cfbd8cbd3c39b79/mummy/routers.nim(271) :anonymous
/home/username/projects/server/api/src/main/nim/server_api/api.nim(65) :anonymous
/home/username/projects/server/api/src/main/nim/server_api/auth.nim(74) extractSession
/home/username/projects/fiber-orm-nim/src/fiber_orm.nim(599) createOrUpdateUser
/home/username/projects/fiber-orm-nim/src/fiber_orm.nim(384) createOrUpdateRecord
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/db_connector-0.1.0-d68319e3785fa937f0465ea915e942b61b6b5442/db_connector/db_postgres.nim(497) getAllRows
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/db_connector-0.1.0-d68319e3785fa937f0465ea915e942b61b6b5442/db_connector/db_postgres.nim(174) setupQuery
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/db_connector-0.1.0-d68319e3785fa937f0465ea915e942b61b6b5442/db_connector/db_postgres.nim(116) dbError
[[reraised from:
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/mummy-0.4.5-cb7f70cd4d6fd3a563e00e664cfbd8cbd3c39b79/mummy.nim(519) workerProc
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/mummy-0.4.5-cb7f70cd4d6fd3a563e00e664cfbd8cbd3c39b79/mummy.nim(450) runTask
/home/username/.local/share/mise/installs/nim/2.2.0/nimble/pkgs2/mummy-0.4.5-cb7f70cd4d6fd3a563e00e664cfbd8cbd3c39b79/mummy/routers.nim(271) :anonymous
/home/username/projects/server/api/src/main/nim/server_api/api.nim(65) :anonymous
/home/username/projects/server/api/src/main/nim/server_api/auth.nim(74) extractSession
/home/username/projects/fiber-orm-nim/src/fiber_orm.nim(727) createOrUpdateUser
]]
Description
Structured Log Formatter - Terminal utility to pretty-print JSON-structured log lines.
Languages
Nim
100%