Allow two getLogger() entrypoints

This commit is contained in:
Gustavo Cordova Avila
2024-04-12 13:40:29 -07:00
parent dfbad6693a
commit a94ac79946
3 changed files with 15 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
# Package
version = "1.1.0"
version = "1.1.1"
author = "Gustavo Cordova Avila"
description = "Simple logging module"
license = "Apache-2.0"

View File

@@ -116,8 +116,13 @@ proc setLogOutputFormat*(fmt: string) =
################################################################
## Create a new logger object.
##
proc getLogger*(name: string; extra: varargs[KVPair]): Logger =
## Return a logger object
proc getLogger*(name: string): Logger =
## Return a logger
new(result)
result.name = name
proc getLogger*(name: string; extra: openarray[KVPair]): Logger =
## Return a logger object with some extra stuff
new(result)
result.name = name
result.extra.add(extra)

View File

@@ -30,4 +30,11 @@ test "Emit different formats":
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.