Initial implementation.

This commit is contained in:
2022-01-13 14:12:10 -06:00
parent 3222260baa
commit 5f21b2f263
4 changed files with 28 additions and 31 deletions

View File

@ -1,7 +1,29 @@
# This is just an example to get you started. A typical library package
# exports the main API in this file. Note that you cannot rename this file
# but you can remove it if you wish.
import logging, sequtils
proc add*(x, y: int): int =
## Adds two files together.
return x + y
type
LoggingNamespace* = ref object
name: string
level*: Level
prependNamespace*: bool
proc initLoggingNamespace*(
name: string,
level = lvlInfo,
prependNamespace = true
): LoggingNamespace =
return LoggingNamespace(
name: name,
level: level,
prependNamespace: prependNamespace)
proc log*(ns: LoggingNamespace, level: Level, args: varargs[string, `$`]) =
if level >= ns.level:
if ns.prependNamespace: log(level, args.mapIt(ns.name & it))
proc debug*(ns: LoggingNamespace, args: varargs[string, `$`]) = log(ns, lvlDebug, args)
proc info*(ns: LoggingNamespace, args: varargs[string, `$`]) = log(ns, lvlInfo, args)
proc notice*(ns: LoggingNamespace, args: varargs[string, `$`]) = log(ns, lvlNotice, args)
proc warn*(ns: LoggingNamespace, args: varargs[string, `$`]) = log(ns, lvlWarn, args)
proc error*(ns: LoggingNamespace, args: varargs[string, `$`]) = log(ns, lvlError, args)
proc fatal*(ns: LoggingNamespace, args: varargs[string, `$`]) = log(ns, lvlFatal, args)

View File

@ -1,12 +0,0 @@
# This is just an example to get you started. Users of your library will
# import this file by writing ``import namespaced_logging/submodule``. Feel free to rename or
# remove this file altogether. You may create additional modules alongside
# this file as required.
type
Submodule* = object
name*: string
proc initSubmodule*(): Submodule =
## Initialises a new ``Submodule`` object.
Submodule(name: "Anonymous")