log debugging stuff

This commit is contained in:
array-in-a-matrix 2024-08-12 13:40:58 -04:00
parent ec6f8fb225
commit 150b2ee436
3 changed files with 23 additions and 4 deletions

View file

@ -18,6 +18,7 @@ type
# general # general
uploadDir*: string uploadDir*: string
enableLogs*: bool enableLogs*: bool
enableDebugLogs*: bool
enableErrorLogs*: bool enableErrorLogs*: bool
@ -55,6 +56,7 @@ proc getConfig(): Cfg =
# general # general
uploadDir: config.get("General", "uploadDir", "./uploads/"), uploadDir: config.get("General", "uploadDir", "./uploads/"),
enableLogs: config.get("General", "enableLogs", true), enableLogs: config.get("General", "enableLogs", true),
enableDebugLogs: config.get("General", "enableDebugLogs", true),
enableErrorLogs: config.get("General", "enableErrorLogs", true), enableErrorLogs: config.get("General", "enableErrorLogs", true),
) )

View file

@ -31,6 +31,8 @@ const defaultConf* =
#uploadDir = "./uploads/" #uploadDir = "./uploads/"
; Allows creating and logging to the log file. If this is on, it forces `enableErrorLogs` on as well. ; Allows creating and logging to the log file. If this is on, it forces `enableErrorLogs` on as well.
#enableLogs = "true" #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. ; Same as `enableLogs` but only for error or fatal messages. Forced on, if `enableLogs` is on.
#enableErrorLogs = "true" #enableErrorLogs = "true"
""" """

View file

@ -2,7 +2,8 @@ import std/[strutils, os, json, asyncdispatch, httpclient, with, logging]
import jester import jester
import checksums/sha3 import checksums/sha3
import norm/[model, postgres] import norm/model
import norm/postgres except error
import ./config/config import ./config/config
import ./[database, helpers] import ./[database, helpers]
@ -27,15 +28,29 @@ const logo = """
const logFormattingString = "[$date $time] - [$levelname]: " const logFormattingString = "[$date $time] - [$levelname]: "
if cfg.enableLogs: 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", addHandler newRollingFileLogger("glimpse-logs.log",
fmtStr = logFormattingString) fmtStr = logFormattingString, levelThreshold = choosenThreshold)
if cfg.enableErrorLogs: if cfg.enableErrorLogs:
addHandler newRollingFileLogger("glimpse-errors.log", addHandler newRollingFileLogger("glimpse-errors.log",
fmtStr = logFormattingString, levelThreshold = lvlError) 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: settings:
bindAddr = cfg.bindAddr bindAddr = cfg.bindAddr