Compare commits
No commits in common. "main" and "0.2.0" have entirely different histories.
@ -1,6 +1,6 @@
|
||||
# Package
|
||||
|
||||
version = "0.2.3"
|
||||
version = "0.2.0"
|
||||
author = "Jonathan Bernard"
|
||||
description = "Small utility to pretty-print strucutured logs."
|
||||
license = "MIT"
|
||||
@ -10,5 +10,5 @@ bin = @["slfmt"]
|
||||
|
||||
# Dependencies
|
||||
|
||||
requires @["nim >= 2.2.0", "docopt >= 0.7.1"]
|
||||
requires @["nim >= 2.2.0", "docopt"]
|
||||
requires @["timeutils", "zero_functional"]
|
||||
|
@ -4,7 +4,7 @@ import docopt, timeutils, zero_functional
|
||||
from std/logging import Level
|
||||
from std/sequtils import toSeq
|
||||
|
||||
const VERSION = "0.2.3"
|
||||
const VERSION = "0.2.0"
|
||||
|
||||
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 + strVal.len + 6 > terminalWidth() or valLines.len > 1:
|
||||
if name.len > 10 or strVal.len + 16 > terminalWidth() or valLines.len > 1:
|
||||
result &= "\n" & valLines.mapIt(" " & it).join("\n") & "\n"
|
||||
else: result &= strVal & "\n"
|
||||
|
||||
@ -98,21 +98,14 @@ proc compactFormat(logJson: JsonNode): string =
|
||||
filter(not ["level", "scope", "ts", "msg"].contains(it[0]))
|
||||
|
||||
let restMsg = join(restNodes -->
|
||||
map("$1: $2" % [
|
||||
decorate(it[0], fgCyan),
|
||||
if it[1].kind == JString: it[1].getStr
|
||||
else: pretty(it[1]),
|
||||
" "]))
|
||||
map("$1: $2" % [decorate(it[0], fgCyan), it[1].getStr]), " ")
|
||||
|
||||
if restMsg.len + result.len + 2 < terminalWidth():
|
||||
result &= " " & restMsg
|
||||
else:
|
||||
var line = " "
|
||||
for (key, val) in restNodes:
|
||||
let fieldVal =
|
||||
if val.kind == JString: val.getStr
|
||||
else: pretty(val)
|
||||
let field = "$1: $2" % [decorate(key, fgCyan), fieldVal]
|
||||
let field = "$1: $2" % [decorate(key, fgCyan), val.getStr]
|
||||
if line.len + field.len + 2 > terminalWidth():
|
||||
result &= "\n " & line
|
||||
line = " "
|
||||
@ -141,8 +134,6 @@ 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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user