removed threadlogging in preference to std/logging

This commit is contained in:
Paul Wilde 2024-08-27 21:39:21 +01:00
parent 287495608a
commit 4bdad20a92
7 changed files with 40 additions and 13 deletions

View file

@ -14,4 +14,3 @@ bin = @["norg"]
requires "nim >= 2.0.0"
requires "parsetoml >= 0.7.1"
requires "argparse >= 4.0.1"
requires "threadlogging"

View file

@ -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(" "))

View file

@ -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:

View file

@ -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]

View file

@ -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

View file

@ -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

View file

@ -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}"