Created
September 27, 2023 18:02
-
-
Save LainLayer/4aa7ce1e47c3486dc6325c20a12958ff to your computer and use it in GitHub Desktop.
Smallest possible nim logging module
This file contains hidden or 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
from strutils import join | |
type Level* = enum | |
debug = "[\e[36mDEBUG\e[0m]: ", # Cyan | |
warn = "[\e[33m WARN\e[0m]: ", # Yellow | |
error = "[\e[31mERROR\e[0m]: ", # Red | |
info = "[\e[34m INFO\e[0m]: ", # Blue | |
ok = "[\e[32m OK\e[0m]: " # Green | |
template toColorString*(input: SomeInteger|SomeFloat): string = "\e[33m" & $input & "\e[0m" | |
template toColorString*(input: static[string]): string = input | |
template toColorString*(input: string): string = "\e[33m'" & input & "'\e[0m" | |
template `()`*(level: static[Level]; text: varargs[string, `toColorString`]) = | |
when not defined(silent) and (level != debug or not defined(release)): | |
echo $level & text.join() | |
else: | |
discard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment