status-im / nim-chronicles

A crafty implementation of structured logging for Nim.
Apache License 2.0
153 stars 20 forks source link

Cannot use strformat with templates #117

Open sillagiusti opened 1 year ago

sillagiusti commented 1 year ago

Hi, I'm trying to use info, debug, error, etc. templates, but if you use strformat on event parameter:

import strformat
import chronicles

let a = 2
info fmt" a = {a}"

compiler says:

Error: internal error: /home/runner/work/nightlies/nightlies/nim-1.6.4/compiler/vmgen.nim(1671, 23)
No stack traceback available
To create a stacktrace, rerun compilation with './koch temp c <file>', see https://nim-lang.github.io/Nim/intern.html#debugging-the-compiler for details
gfrewqpoiu commented 1 year ago

This is actually my main issue as well at the moment, the log message needs to be a static[string] which basically means any runtime string manipulation like formatted strings or reading strings from a variable (that is not const) is not possible. (basically all log messages must be const)

ringabout commented 1 year ago

Yeah, it needs to be a const and the devel compiler gives the expected type mismatch errors.

Workaround:

import strformat
import chronicles

const a = 2
info static(fmt" a = {a}")