From 150b2ee4360716d343ee7208730079962a45b0d0 Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Mon, 12 Aug 2024 13:40:58 -0400 Subject: [PATCH] log debugging stuff --- src/config/config.nim | 2 ++ src/config/defConf.nim | 2 ++ src/glimpse.nim | 23 +++++++++++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/config/config.nim b/src/config/config.nim index 666ab91..78cd864 100644 --- a/src/config/config.nim +++ b/src/config/config.nim @@ -18,6 +18,7 @@ type # general uploadDir*: string enableLogs*: bool + enableDebugLogs*: bool enableErrorLogs*: bool @@ -55,6 +56,7 @@ proc getConfig(): Cfg = # general uploadDir: config.get("General", "uploadDir", "./uploads/"), enableLogs: config.get("General", "enableLogs", true), + enableDebugLogs: config.get("General", "enableDebugLogs", true), enableErrorLogs: config.get("General", "enableErrorLogs", true), ) diff --git a/src/config/defConf.nim b/src/config/defConf.nim index 031ddca..a3c5d17 100644 --- a/src/config/defConf.nim +++ b/src/config/defConf.nim @@ -31,6 +31,8 @@ const defaultConf* = #uploadDir = "./uploads/" ; Allows creating and logging to the log file. If this is on, it forces `enableErrorLogs` on as well. #enableLogs = "true" +; Includes debugging messages in logs. +#enableDebugLogs = "true" ; Same as `enableLogs` but only for error or fatal messages. Forced on, if `enableLogs` is on. #enableErrorLogs = "true" """ diff --git a/src/glimpse.nim b/src/glimpse.nim index 8d52bca..f46e816 100644 --- a/src/glimpse.nim +++ b/src/glimpse.nim @@ -2,7 +2,8 @@ import std/[strutils, os, json, asyncdispatch, httpclient, with, logging] import jester import checksums/sha3 -import norm/[model, postgres] +import norm/model +import norm/postgres except error import ./config/config import ./[database, helpers] @@ -27,15 +28,29 @@ const logo = """ const logFormattingString = "[$date $time] - [$levelname]: " if cfg.enableLogs: - addHandler newConsoleLogger(fmtStr = logFormattingString) + var choosenThreshold: Level + if cfg.enableDebugLogs: + choosenThreshold = lvlDebug + else: + choosenThreshold = lvlInfo + + addHandler newConsoleLogger(fmtStr = logFormattingString, + levelThreshold = choosenThreshold) addHandler newRollingFileLogger("glimpse-logs.log", - fmtStr = logFormattingString) + fmtStr = logFormattingString, levelThreshold = choosenThreshold) if cfg.enableErrorLogs: addHandler newRollingFileLogger("glimpse-errors.log", fmtStr = logFormattingString, levelThreshold = lvlError) -log(lvlAll, logo) +debug "Debug logs enabled!" +info "Info logs enabled!" +notice "Notice logs enabled!" +warn "Warn logs enabled!" +error "Error logs enabled!" +fatal "Fatal logs enabled!" + +notice logo settings: bindAddr = cfg.bindAddr