Initial implementation.
This commit is contained in:
parent
3222260baa
commit
5f21b2f263
@ -1,7 +1,29 @@
|
|||||||
# This is just an example to get you started. A typical library package
|
import logging, sequtils
|
||||||
# exports the main API in this file. Note that you cannot rename this file
|
|
||||||
# but you can remove it if you wish.
|
|
||||||
|
|
||||||
proc add*(x, y: int): int =
|
type
|
||||||
## Adds two files together.
|
LoggingNamespace* = ref object
|
||||||
return x + y
|
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)
|
||||||
|
@ -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")
|
|
@ -1 +0,0 @@
|
|||||||
switch("path", "$projectDir/../src")
|
|
@ -1,12 +0,0 @@
|
|||||||
# This is just an example to get you started. You may wish to put all of your
|
|
||||||
# tests into a single file, or separate them into multiple `test1`, `test2`
|
|
||||||
# etc. files (better names are recommended, just make sure the name starts with
|
|
||||||
# the letter 't').
|
|
||||||
#
|
|
||||||
# To run these tests, simply execute `nimble test`.
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
import namespaced_logging
|
|
||||||
test "can add":
|
|
||||||
check add(5, 5) == 10
|
|
Loading…
x
Reference in New Issue
Block a user