diff --git a/norg.nimble b/norg.nimble index 9d07872..89f62c1 100644 --- a/norg.nimble +++ b/norg.nimble @@ -14,4 +14,3 @@ bin = @["norg"] requires "nim >= 2.0.0" requires "parsetoml >= 0.7.1" requires "argparse >= 4.0.1" -requires "threadlogging" diff --git a/norg/model/log_type.nim b/norg/model/log_type.nim index c51634b..dd63b73 100644 --- a/norg/model/log_type.nim +++ b/norg/model/log_type.nim @@ -1,15 +1,21 @@ import logging -import threadlogging - -export logging.newConsoleLogger -export logging.newFileLogger -export threadlogging +#import threadlogging +import strutils type LogInfo* = object level*: Level file*: string +var logger*: ConsoleLogger +proc initLogger*(level: Level = lvlInfo, strfmt: string = "[$levelname] ") = + logger = newConsoleLogger(level, strfmt) + logger.log(lvlNotice, "Log Level: ", $level) + +#proc initLoggerThread*(level: Level = lvlInfo, strfmt: string = "[$levelname] ") = +# initLogThread(strfmt, level) +# threadlogging.notice("Log Level: ", $level) + proc newLogInfo*(): LogInfo = var log = LogInfo() log.level = lvlInfo @@ -19,4 +25,24 @@ proc newLogInfo*(): LogInfo = proc toLogLevel*(s: string): Level = for l in Level.items: if s == $l: return l + case s + of "debug": return lvlDebug + of "info": return lvlInfo + of "warn": return lvlWarn + of "error": return lvlError + of "fatal": return lvlFatal + of "notice": return lvlNotice return lvlInfo + +proc debug*(args: varargs[string,`$`]) = + logger.log(lvlDebug, args.join(" ")) +proc fatal*(args: varargs[string,`$`]) = + logger.log(lvlfatal, args.join(" ")) +proc warn*(args: varargs[string,`$`]) = + logger.log(lvlwarn, args.join(" ")) +proc notice*(args: varargs[string,`$`]) = + logger.log(lvlnotice, args.join(" ")) +proc info*(args: varargs[string,`$`]) = + logger.log(lvlinfo, args.join(" ")) +proc error*(args: varargs[string,`$`]) = + logger.log(lvlerror, args.join(" ")) diff --git a/norg/norg.nim b/norg/norg.nim index bd02de9..69c72d1 100644 --- a/norg/norg.nim +++ b/norg/norg.nim @@ -11,8 +11,8 @@ proc showVersion() = echo "Norg Version: ", VERSION quit(0) -proc startLogger(nc: NorgConfig) = - initLogThread("[$levelname] ", nc.log_info.level) +proc startLogger(log_info: LogInfo) = + initLogger(log_info.level, "[$levelname] ") proc start() = parseArgs() @@ -21,7 +21,8 @@ proc start() = showVersion() elif norg_args.config_file != "": norg_config = parseConfigFile(norg_args.config_file) - startLogger(norg_config) + echo norg_config.log_info.level + startLogger(norg_config.log_info) if norg_config.source_directories.len > 0 and norg_config.repositories.len > 0: run_actions(norg_config.actions.before_everything) for repo in norg_config.repositories: diff --git a/norg/restic/mount.nim b/norg/restic/mount.nim index 52d821c..be81a9b 100644 --- a/norg/restic/mount.nim +++ b/norg/restic/mount.nim @@ -1,8 +1,8 @@ import ../model/config_type +import ../model/log_type import execute import strformat -import threadlogging proc mountSnapshot*(nc: NorgConfig, repo: Repository): int = #let further_args = nc.args.further_args[1..^1] diff --git a/norg/restic/restic.nim b/norg/restic/restic.nim index 67fc575..4916ee0 100644 --- a/norg/restic/restic.nim +++ b/norg/restic/restic.nim @@ -1,5 +1,6 @@ import ../model/config_type import ../utils/actions +import ../model/log_type import init import backup @@ -8,7 +9,6 @@ import mount import restore import prune -import threadlogging proc execute*(nc: NorgConfig, repo: Repository) = case nc.args.command diff --git a/norg/restic/restore.nim b/norg/restic/restore.nim index b600d6b..14a5c1c 100644 --- a/norg/restic/restore.nim +++ b/norg/restic/restore.nim @@ -1,9 +1,10 @@ import ../model/config_type +import ../model/log_type + import execute import strformat import os -import threadlogging proc isEmpty(dir: string): bool = var count = 0 diff --git a/norg/utils/run.nim b/norg/utils/run.nim index c4d951c..53b31b3 100644 --- a/norg/utils/run.nim +++ b/norg/utils/run.nim @@ -1,6 +1,6 @@ import strformat import osproc -import threadlogging +import ../model/log_type proc run*(cmd: string): int = debug fmt"Trying to run : {cmd}"