diff --git a/src/namespaced_logging.nim b/src/namespaced_logging.nim index 4b2a270..eda008d 100644 --- a/src/namespaced_logging.nim +++ b/src/namespaced_logging.nim @@ -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) diff --git a/src/namespaced_logging/submodule.nim b/src/namespaced_logging/submodule.nim deleted file mode 100644 index de1756a..0000000 --- a/src/namespaced_logging/submodule.nim +++ /dev/null @@ -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") diff --git a/tests/config.nims b/tests/config.nims deleted file mode 100644 index 3bb69f8..0000000 --- a/tests/config.nims +++ /dev/null @@ -1 +0,0 @@ -switch("path", "$projectDir/../src") \ No newline at end of file diff --git a/tests/test1.nim b/tests/test1.nim deleted file mode 100644 index 63cf8dd..0000000 --- a/tests/test1.nim +++ /dev/null @@ -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