Skip to content

Commit

Permalink
Explicitly bind logging procs in templates (#168)
Browse files Browse the repository at this point in the history
* Explicitly bind logging procs in templates

The logging templates in `logger` reference procs like `error`, `info`, `warn` etc. from the `logging` module. These are implicitly bound, as they have exactly 1 overload in the scope of the template definitions (nim-lang/Nim#11184).

If this behavior of Nim or the context in `logger` were to change, these would start preferring procs like `macros.error` instead and cause issues. Explicitly binding them keeps the current behavior consistent.

An alternative would be to directly call `logging.error join(args)` etc.

* also update frameLog
  • Loading branch information
metagn committed Sep 30, 2023
1 parent 4fec67d commit 4a014d6
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/nimlsppkg/logger.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,31 @@ let rollingLog = newRollingFileLogger(storage / "nimlsp.log")
addHandler(rollingLog)

template debugLog*(args: varargs[string, `$`]) =
bind debug
when defined(debugLogging):
debug join(args)
flushFile rollingLog.file

template infoLog*(args: varargs[string, `$`]) =
bind info
when defined(debugLogging):
info join(args)
flushFile rollingLog.file

template errorLog*(args: varargs[string, `$`]) =
bind error
when defined(debugLogging):
error join(args)

template warnLog*(args: varargs[string, `$`]) =
bind warn
when defined(debugLogging):
warn join(args)

type FrameDirection* = enum In, Out

template frameLog*(direction: FrameDirection, args: varargs[string, `$`]) =
bind info
let oldFmtStr = rollingLog.fmtStr
case direction:
of Out: rollingLog.fmtStr = "<< "
Expand Down

0 comments on commit 4a014d6

Please sign in to comment.