Created
August 8, 2018 14:09
-
-
Save copygirl/811c025807053db7fa2a78c68f895db7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... util/log.nim(24, 24) Error: internal error: expr: var not init sevColor_994035 | |
... Traceback from system (most recent call last) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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