Last active
March 30, 2021 23:44
-
-
Save iamnoah/12d87b035a0f02f1bd223e48179fefe9 to your computer and use it in GitHub Desktop.
Formats JSON log lines (naively assumed to start with "{") in console output while preserving the non-JSON lines
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
jlog() { | |
local FORMAT=${FORMAT:-'"\(.timestamp) \(.level)\t - \(.name) - \(.message)\t\t\(del(.timestamp, .message, .level, .name, .traceback))\(if .traceback then "\r\n\(.traceback | gsub("\n"; "\r\n"))" else "" end)\r"'} | |
tee >( grep --line-buffered -v "^{" > /dev/tty ) | grep --line-buffered "^{" | jq --raw-output --unbuffered "$FORMAT" | |
} | |
# USAGE: command that prints json logs | jlog |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment