Files
simple-log/tests/test1.nim
2024-04-12 13:40:29 -07:00

41 lines
1.3 KiB
Nim

import unittest
import ../src/logging
test "Emit logging messages":
var log = getLogger("main", {"extra1": "one", "extra2": "two"})
log.always "This is an info message"
test "Shorthand methods":
var log = getLogger("shorthand")
log.always("This should always appear")
log.fatal("Such a terrible thing, a FATAL error; bye?")
log.critical("The engines are at CRITICAL level!!")
log.error("Something went wrong, I caught an ERROR")
log.warning("This is your first WARNING, ok?")
log.warn("This is your second WARNING, ok?")
log.quiet("Something important, say it QUIET")
log.info("Some INFOrmational data")
log.noisy("Level is low enough that it's NOISY")
log.debug("I don't see this unless I'm DEBUGging")
log.trace("We're TRACEing the code as we speak")
test "Emit different levels":
var log = getLogger("levels")
for l in LogLevel:
log.write(l, "level example", {"log-level": $l})
test "Emit different formats":
var log = getLogger("formats")
for fmt in LogOutputFormat:
setLogOutputFormat(fmt)
log.always("format example", {"format": $fmt})
test "With and without extra":
var log1 = getLogger("with-extra", {"extra": "yes"})
var log2 = getLogger("without-extra")
log1.always("Just a message", {"more-extra": "please more"})
log2.always("Another message", {"extra-filling": "dessert"})
# Fin.