2 Commits
0.2.0 ... 0.2.2

Author SHA1 Message Date
2291b75c0a Tweak line wrapping for long-keyed, short-values fields. 2025-01-20 23:06:07 -06:00
11cc9c9a39 Fix bug when a line happens to parse as JSON but isn't an object.
For example, if `false` happened to be the only value on a line, this
would be parsed as valid JSON (a boolean) but it is not a structured log
message that slfmt should try to parse and format.
2025-01-20 21:24:22 -06:00
2 changed files with 5 additions and 3 deletions

View File

@ -1,6 +1,6 @@
# Package
version = "0.2.0"
version = "0.2.2"
author = "Jonathan Bernard"
description = "Small utility to pretty-print strucutured logs."
license = "MIT"

View File

@ -4,7 +4,7 @@ import docopt, timeutils, zero_functional
from std/logging import Level
from std/sequtils import toSeq
const VERSION = "0.2.0"
const VERSION = "0.2.2"
const USAGE = """Usage:
slfmt [options]
@ -63,7 +63,7 @@ proc fullFormatField(name: string, value: JsonNode): string =
else: strVal = pretty(value)
let valLines = splitLines(strVal)
if name.len > 10 or strVal.len + 16 > terminalWidth() or valLines.len > 1:
if name.len + strVal.len + 6 > terminalWidth() or valLines.len > 1:
result &= "\n" & valLines.mapIt(" " & it).join("\n") & "\n"
else: result &= strVal & "\n"
@ -134,6 +134,8 @@ when isMainModule:
while(sin.readLine(line)):
try:
let logJson = parseLogLine(line)
if logJson.kind != JObject:
raise newException(JsonParsingError, "Expected a JSON object")
if logLevel.isSome and logJson.hasKey("level"):
let lvl = parseLogLevel(logJson["level"].getStr)