From a7e8f3add0a528a3459cbe12f0480ca5fca86bb2 Mon Sep 17 00:00:00 2001 From: kuu7o Date: Tue, 18 Nov 2025 22:14:52 -0300 Subject: [PATCH] feat(conf): ability to set log level in config --- nitter.example.conf | 1 + src/config.nim | 1 + src/nitter.nim | 15 +++++++++++---- src/types.nim | 1 + 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/nitter.example.conf b/nitter.example.conf index 397d9be..fda8897 100644 --- a/nitter.example.conf +++ b/nitter.example.conf @@ -24,6 +24,7 @@ hmacKey = "secretkey" # random key for cryptographic signing of video urls base64Media = false # use base64 encoding for proxied media urls enableRSS = true # set this to false to disable RSS feeds enableDebug = false # enable request logs and debug endpoints (/.sessions) +logLevel = "info" # log level (debug, info, warn, error, fatal) proxy = "" # http/https url, SOCKS proxies are not supported proxyAuth = "" diff --git a/src/config.nim b/src/config.nim index 1b05ffe..7325a65 100644 --- a/src/config.nim +++ b/src/config.nim @@ -39,6 +39,7 @@ proc getConfig*(path: string): (Config, parseCfg.Config) = minTokens: cfg.get("Config", "tokenCount", 10), enableRss: cfg.get("Config", "enableRSS", true), enableDebug: cfg.get("Config", "enableDebug", false), + logLevel: cfg.get("Config", "logLevel", ""), proxy: cfg.get("Config", "proxy", ""), proxyAuth: cfg.get("Config", "proxyAuth", "") ) diff --git a/src/nitter.nim b/src/nitter.nim index 61d4df5..5625924 100644 --- a/src/nitter.nim +++ b/src/nitter.nim @@ -52,10 +52,17 @@ initSessionPool(cfg, sessionsPath) addHandler(new(ColoredLogger)) -if cfg.enableDebug: - setLogFilter(lvlDebug) -else: - setLogFilter(lvlInfo) +let level = case cfg.logLevel.toLowerAscii + of "debug": lvlDebug + of "info": lvlInfo + of "warn": lvlWarn + of "error": lvlError + of "fatal": lvlFatal + of "none": lvlNone + else: + if cfg.enableDebug: lvlDebug else: lvlInfo + +setLogFilter(level) info &"Starting Nitter at {getUrlPrefix(cfg)}" diff --git a/src/types.nim b/src/types.nim index 5a08bb7..0b3b5a7 100644 --- a/src/types.nim +++ b/src/types.nim @@ -285,6 +285,7 @@ type minTokens*: int enableRss*: bool enableDebug*: bool + logLevel*: string proxy*: string proxyAuth*: string