Skip to content

Commit

Permalink
suppress some more IOError when logging
Browse files Browse the repository at this point in the history
Nim 2.0 highlighted some more situations where logging may raise an
`IOError`. Suppress those as well to compile applications in Nim 2.0.
  • Loading branch information
etan-status committed Aug 17, 2023
1 parent c9c8e58 commit 08f9c26
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions chronicles/log_output.nim
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,10 @@ template writeTs(record) =

template fgColor(record, color, brightness) =
when record.colors == AnsiColors:
append(record.output, ansiForegroundColorCode(color, brightness))
try:
append(record.output, ansiForegroundColorCode(color, brightness))
except ValueError:
discard
elif record.colors == NativeColors:
setForegroundColor(getOutputStream(record.output), color, brightness)

Expand Down Expand Up @@ -548,7 +551,8 @@ proc initLogRecord*(r: var TextLineRecord,
r.level = lvl
appendHeader(r, lvl, topics, name, true)

proc setProperty*(r: var TextLineRecord, key: string, val: auto) =
proc setProperty*(
r: var TextLineRecord, key: string, val: auto) {.raises: [].} =
append(r.output, " ")
let valText = $val

Expand Down Expand Up @@ -608,7 +612,8 @@ proc initLogRecord*(r: var TextBlockRecord,
appendHeader(r, level, topics, name, false)
append(r.output, "\n")

proc setProperty*(r: var TextBlockRecord, key: string, val: auto) =
proc setProperty*(
r: var TextBlockRecord, key: string, val: auto) {.raises: [].} =
let valText = $val

append(r.output, textBlockIndent)
Expand Down Expand Up @@ -649,7 +654,10 @@ template `[]=`(r: var JsonRecord, key: string, val: auto) =
else:
r.record[key] = val
else:
writeField(r.jsonWriter, key, val)
try:
writeField(r.jsonWriter, key, val)
except IOError:
discard

proc initLogRecord*(r: var JsonRecord,
level: LogLevel,
Expand All @@ -673,7 +681,7 @@ proc initLogRecord*(r: var JsonRecord,
if topics.len > 0:
r["topics"] = topics

proc setProperty*(r: var JsonRecord, key: string, val: auto) =
proc setProperty*(r: var JsonRecord, key: string, val: auto) {.raises: [].} =
r[key] = val

template setFirstProperty*(r: var JsonRecord, key: string, val: auto) =
Expand Down

0 comments on commit 08f9c26

Please sign in to comment.