Allow two getLogger() entrypoints
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# Package
|
# Package
|
||||||
version = "1.1.0"
|
version = "1.1.1"
|
||||||
author = "Gustavo Cordova Avila"
|
author = "Gustavo Cordova Avila"
|
||||||
description = "Simple logging module"
|
description = "Simple logging module"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
|||||||
@@ -116,8 +116,13 @@ proc setLogOutputFormat*(fmt: string) =
|
|||||||
################################################################
|
################################################################
|
||||||
## Create a new logger object.
|
## Create a new logger object.
|
||||||
##
|
##
|
||||||
proc getLogger*(name: string; extra: varargs[KVPair]): Logger =
|
proc getLogger*(name: string): Logger =
|
||||||
## Return a logger object
|
## 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)
|
new(result)
|
||||||
result.name = name
|
result.name = name
|
||||||
result.extra.add(extra)
|
result.extra.add(extra)
|
||||||
|
|||||||
@@ -30,4 +30,11 @@ test "Emit different formats":
|
|||||||
setLogOutputFormat(fmt)
|
setLogOutputFormat(fmt)
|
||||||
log.always("format example", {"format": $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.
|
# Fin.
|
||||||
|
|||||||
Reference in New Issue
Block a user