removed threadlogging in preference to std/logging
This commit is contained in:
parent
287495608a
commit
4bdad20a92
7 changed files with 40 additions and 13 deletions
|
@ -14,4 +14,3 @@ bin = @["norg"]
|
||||||
requires "nim >= 2.0.0"
|
requires "nim >= 2.0.0"
|
||||||
requires "parsetoml >= 0.7.1"
|
requires "parsetoml >= 0.7.1"
|
||||||
requires "argparse >= 4.0.1"
|
requires "argparse >= 4.0.1"
|
||||||
requires "threadlogging"
|
|
||||||
|
|
|
@ -1,15 +1,21 @@
|
||||||
import logging
|
import logging
|
||||||
import threadlogging
|
#import threadlogging
|
||||||
|
import strutils
|
||||||
export logging.newConsoleLogger
|
|
||||||
export logging.newFileLogger
|
|
||||||
export threadlogging
|
|
||||||
|
|
||||||
type
|
type
|
||||||
LogInfo* = object
|
LogInfo* = object
|
||||||
level*: Level
|
level*: Level
|
||||||
file*: string
|
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 =
|
proc newLogInfo*(): LogInfo =
|
||||||
var log = LogInfo()
|
var log = LogInfo()
|
||||||
log.level = lvlInfo
|
log.level = lvlInfo
|
||||||
|
@ -19,4 +25,24 @@ proc newLogInfo*(): LogInfo =
|
||||||
proc toLogLevel*(s: string): Level =
|
proc toLogLevel*(s: string): Level =
|
||||||
for l in Level.items:
|
for l in Level.items:
|
||||||
if s == $l: return l
|
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
|
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(" "))
|
||||||
|
|
|
@ -11,8 +11,8 @@ proc showVersion() =
|
||||||
echo "Norg Version: ", VERSION
|
echo "Norg Version: ", VERSION
|
||||||
quit(0)
|
quit(0)
|
||||||
|
|
||||||
proc startLogger(nc: NorgConfig) =
|
proc startLogger(log_info: LogInfo) =
|
||||||
initLogThread("[$levelname] ", nc.log_info.level)
|
initLogger(log_info.level, "[$levelname] ")
|
||||||
|
|
||||||
proc start() =
|
proc start() =
|
||||||
parseArgs()
|
parseArgs()
|
||||||
|
@ -21,7 +21,8 @@ proc start() =
|
||||||
showVersion()
|
showVersion()
|
||||||
elif norg_args.config_file != "":
|
elif norg_args.config_file != "":
|
||||||
norg_config = parseConfigFile(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:
|
if norg_config.source_directories.len > 0 and norg_config.repositories.len > 0:
|
||||||
run_actions(norg_config.actions.before_everything)
|
run_actions(norg_config.actions.before_everything)
|
||||||
for repo in norg_config.repositories:
|
for repo in norg_config.repositories:
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import ../model/config_type
|
import ../model/config_type
|
||||||
|
import ../model/log_type
|
||||||
import execute
|
import execute
|
||||||
import strformat
|
import strformat
|
||||||
|
|
||||||
import threadlogging
|
|
||||||
|
|
||||||
proc mountSnapshot*(nc: NorgConfig, repo: Repository): int =
|
proc mountSnapshot*(nc: NorgConfig, repo: Repository): int =
|
||||||
#let further_args = nc.args.further_args[1..^1]
|
#let further_args = nc.args.further_args[1..^1]
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import ../model/config_type
|
import ../model/config_type
|
||||||
import ../utils/actions
|
import ../utils/actions
|
||||||
|
import ../model/log_type
|
||||||
|
|
||||||
import init
|
import init
|
||||||
import backup
|
import backup
|
||||||
|
@ -8,7 +9,6 @@ import mount
|
||||||
import restore
|
import restore
|
||||||
import prune
|
import prune
|
||||||
|
|
||||||
import threadlogging
|
|
||||||
|
|
||||||
proc execute*(nc: NorgConfig, repo: Repository) =
|
proc execute*(nc: NorgConfig, repo: Repository) =
|
||||||
case nc.args.command
|
case nc.args.command
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import ../model/config_type
|
import ../model/config_type
|
||||||
|
import ../model/log_type
|
||||||
|
|
||||||
import execute
|
import execute
|
||||||
import strformat
|
import strformat
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import threadlogging
|
|
||||||
|
|
||||||
proc isEmpty(dir: string): bool =
|
proc isEmpty(dir: string): bool =
|
||||||
var count = 0
|
var count = 0
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import strformat
|
import strformat
|
||||||
import osproc
|
import osproc
|
||||||
import threadlogging
|
import ../model/log_type
|
||||||
|
|
||||||
proc run*(cmd: string): int =
|
proc run*(cmd: string): int =
|
||||||
debug fmt"Trying to run : {cmd}"
|
debug fmt"Trying to run : {cmd}"
|
||||||
|
|
Loading…
Reference in a new issue