adding prelim procs for using a log file

This commit is contained in:
Paul Wilde 2024-09-11 21:08:27 +01:00
parent 0adf07a7ed
commit 2215d5b150
3 changed files with 28 additions and 5 deletions

@ -1 +1 @@
Subproject commit 9b5c6dd04825d33cb27a9c6715764ad7e23182c4 Subproject commit b7d436287a9ecbe87466babf56d81f3c9fb56959

View file

@ -8,9 +8,15 @@ type
file*: string file*: string
var logger*: ConsoleLogger var logger*: ConsoleLogger
proc initLogger*(level: Level = lvlInfo, strfmt: string = "[$levelname] ") = var filelogger*: FileLogger
proc initLogger*(level: Level = lvlInfo, strfmt: string = "[$levelname] ", log_file: string = "") =
logger = newConsoleLogger(level, strfmt) logger = newConsoleLogger(level, strfmt)
logger.log(lvlNotice, "Log Level: ", $level) logger.log(lvlNotice, "Log Level: ", $level)
if log_file != "":
let str = "$time " & strfmt
filelogger = newFileLogger(log_file, levelThreshold=level, fmtStr=str)
filelogger.log(lvlNotice, "Log Level: ", $level)
#proc initLoggerThread*(level: Level = lvlInfo, strfmt: string = "[$levelname] ") = #proc initLoggerThread*(level: Level = lvlInfo, strfmt: string = "[$levelname] ") =
# initLogThread(strfmt, level) # initLogThread(strfmt, level)
@ -36,13 +42,30 @@ proc toLogLevel*(s: string): Level =
proc debug*(args: varargs[string,`$`]) = proc debug*(args: varargs[string,`$`]) =
logger.log(lvlDebug, args.join(" ")) logger.log(lvlDebug, args.join(" "))
if filelogger != nil:
filelogger.log(lvlDebug, args.join(" "))
proc fatal*(args: varargs[string,`$`]) = proc fatal*(args: varargs[string,`$`]) =
logger.log(lvlfatal, args.join(" ")) logger.log(lvlFatal, args.join(" "))
if filelogger != nil:
filelogger.log(lvlFatal, args.join(" "))
proc warn*(args: varargs[string,`$`]) = proc warn*(args: varargs[string,`$`]) =
logger.log(lvlwarn, args.join(" ")) logger.log(lvlwarn, args.join(" "))
if filelogger != nil:
filelogger.log(lvlWarn, args.join(" "))
proc notice*(args: varargs[string,`$`]) = proc notice*(args: varargs[string,`$`]) =
logger.log(lvlnotice, args.join(" ")) logger.log(lvlnotice, args.join(" "))
if filelogger != nil:
filelogger.log(lvlNotice, args.join(" "))
proc info*(args: varargs[string,`$`]) = proc info*(args: varargs[string,`$`]) =
logger.log(lvlinfo, args.join(" ")) logger.log(lvlinfo, args.join(" "))
if filelogger != nil:
filelogger.log(lvlInfo, args.join(" "))
proc error*(args: varargs[string,`$`]) = proc error*(args: varargs[string,`$`]) =
logger.log(lvlerror, args.join(" ")) logger.log(lvlerror, args.join(" "))
if filelogger != nil:
filelogger.log(lvlError, args.join(" "))

View file

@ -11,7 +11,7 @@ proc showVersion() =
echo "Norg Version: ", VERSION echo "Norg Version: ", VERSION
quit(0) quit(0)
proc startLogger(log_info: LogInfo) = proc startLogger(nc: NorgConfig, log_info: LogInfo) =
initLogger(log_info.level, "[$levelname] ") initLogger(log_info.level, "[$levelname] ")
proc start() = proc start() =
@ -22,7 +22,7 @@ proc start() =
elif norg_args.config_file != "": elif norg_args.config_file != "":
norg_config = parseConfigFile(norg_args.config_file) norg_config = parseConfigFile(norg_args.config_file)
echo norg_config.log_info.level echo norg_config.log_info.level
startLogger(norg_config.log_info) norg_config.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: