Skip to content

Commit 1b559ee

Browse files
authored
fix: nim build (libp2p#333)
1 parent 0671a70 commit 1b559ee

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

nim-peer/config.nims

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
when withDir(thisDir(), system.fileExists("nimble.paths")):
33
include "nimble.paths"
44
--define:
5-
"chronicles_sinks=textblocks[dynamic]"
5+
"chronicles_sinks=json[dynamic]"
66
--define:
77
"chronicles_log_level=DEBUG"
88
# end Nimble config

nim-peer/src/nim_peer.nim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,24 @@ proc start(
8282
# Handle Ctrl+C
8383
setControlCHook(cleanup)
8484

85+
# Pick the correct string type for your Chronicles version
86+
when declared(OutStr):
87+
type WriterStr = OutStr
88+
else:
89+
type WriterStr = LogOutputStr
90+
91+
# Early (bootstrap) writer: mirror logs to stdout so nothing is dropped
92+
defaultChroniclesStream.output.writer =
93+
proc (lvl: LogLevel, rec: WriterStr) {.closure, gcsafe, raises: [].} =
94+
let s = cast[string](rec)
95+
try:
96+
for line in s.splitLines():
97+
stdout.writeLine(line)
98+
stdout.flushFile()
99+
except IOError:
100+
discard
101+
102+
85103
var rng = newRng()
86104

87105
let switch =

0 commit comments

Comments
 (0)