Skip to content

Instantly share code, notes, and snippets.

@copygirl
Created August 8, 2018 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save copygirl/811c025807053db7fa2a78c68f895db7 to your computer and use it in GitHub Desktop.
Save copygirl/811c025807053db7fa2a78c68f895db7 to your computer and use it in GitHub Desktop.
... util/log.nim(24, 24) Error: internal error: expr: var not init sevColor_994035
... Traceback from system (most recent call last)
import
macros,
strutils,
terminal
type LogSeverity* = enum
sevError = "Error"
sevWarn = "Warn"
sevInfo = "Info"
sevDebug = "Debug"
macro log*(severity: static[LogSeverity], group: static[string], m: varargs[typed]): untyped =
let sevStr = align("[" & toUpperAscii($severity) & "] ", 8)
let sevColor = case severity
of sevError: fgRed
of sevWarn: fgYellow
of sevInfo: fgWhite
of sevDebug: fgBlack
let groupStr = "[" & $group & "] "
result = quote do:
setStyle({ styleBright })
setForegroundColor(sevColor)
write(stdout, sevStr)
setStyle({ styleDim })
setForegroundColor(fgWhite)
write(stdout, groupStr)
let wl = newCall(bindSym"styledWriteLine", bindSym"stdout")
for arg in m: wl.add(arg)
result.add(wl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment