tmacro8.nim 804 B

123456789101112131415161718192021222324252627282930313233343536
  1. # issue #8573
  2. import
  3. macros,
  4. strutils,
  5. terminal
  6. type LogSeverity* = enum
  7. sevError = "Error"
  8. sevWarn = "Warn"
  9. sevInfo = "Info"
  10. sevDebug = "Debug"
  11. macro log*(severity: static[LogSeverity], group: static[string], m: varargs[typed]): untyped =
  12. let sevStr = align("[" & toUpperAscii($severity) & "] ", 8)
  13. let sevColor = case severity
  14. of sevError: fgRed
  15. of sevWarn: fgYellow
  16. of sevInfo: fgWhite
  17. of sevDebug: fgBlack
  18. let groupStr = "[" & $group & "] "
  19. result = quote do:
  20. setStyle({ styleBright })
  21. setForegroundColor(sevColor) # <==
  22. write(stdout, sevStr)
  23. setStyle({ styleDim })
  24. setForegroundColor(fgWhite)
  25. write(stdout, groupStr)
  26. let wl = newCall(bindSym"styledWriteLine", bindSym"stdout")
  27. for arg in m: wl.add(arg)
  28. result.add(wl)