From 18cf95ed77488049023dc7f0c5ae147dbb9ce264 Mon Sep 17 00:00:00 2001 From: Zed Date: Wed, 5 Jan 2022 19:08:08 +0100 Subject: [PATCH] Add enableDebug config to turn on logs --- nitter.example.conf | 11 ++++++----- src/config.nim | 23 +++++++++++++---------- src/nitter.nim | 5 ++--- src/types.nim | 1 + 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/nitter.example.conf b/nitter.example.conf index 93526b4..0ed6ed0 100644 --- a/nitter.example.conf +++ b/nitter.example.conf @@ -10,20 +10,21 @@ hostname = "nitter.net" [Cache] listMinutes = 240 # how long to cache list info (not the tweets, so keep it high) rssMinutes = 10 # how long to cache rss queries -redisHost = "localhost" # Change to "redis" if using docker-compose +redisHost = "localhost" # Change to "redis" if using docker-compose redisPort = 6379 redisPassword = "" -redisConnections = 20 # connection pool size +redisConnections = 20 # connection pool size redisMaxConnections = 30 # max, new connections are opened when none are available, but if the pool size # goes above this, they're closed when released. don't worry about this unless # you receive tons of requests per second [Config] -hmacKey = "secretkey" # random key for cryptographic signing of video urls -base64Media = false # use base64 encoding for proxied media urls +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 -proxy = "" # proxy type http/https +enableDebug = false # enable request logs and debug endpoints +proxy = "" # http/https url, SOCKS proxies are not supported proxyAuth = "" tokenCount = 10 # minimum amount of usable tokens. tokens are used to authorize API requests, diff --git a/src/config.nim b/src/config.nim index bb60a74..1b05ffe 100644 --- a/src/config.nim +++ b/src/config.nim @@ -14,22 +14,16 @@ proc getConfig*(path: string): (Config, parseCfg.Config) = var cfg = loadConfig(path) let conf = Config( + # Server address: cfg.get("Server", "address", "0.0.0.0"), port: cfg.get("Server", "port", 8080), useHttps: cfg.get("Server", "https", true), httpMaxConns: cfg.get("Server", "httpMaxConnections", 100), - + staticDir: cfg.get("Server", "staticDir", "./public"), title: cfg.get("Server", "title", "Nitter"), hostname: cfg.get("Server", "hostname", "nitter.net"), - staticDir: cfg.get("Server", "staticDir", "./public"), - - hmacKey: cfg.get("Config", "hmacKey", "secretkey"), - base64Media: cfg.get("Config", "base64Media", false), - minTokens: cfg.get("Config", "tokenCount", 10), - enableRss: cfg.get("Config", "enableRSS", true), - proxy: cfg.get("Config", "proxy", ""), - proxyAuth: cfg.get("Config", "proxyAuth", ""), + # Cache listCacheTime: cfg.get("Cache", "listMinutes", 120), rssCacheTime: cfg.get("Cache", "rssMinutes", 10), @@ -37,7 +31,16 @@ proc getConfig*(path: string): (Config, parseCfg.Config) = redisPort: cfg.get("Cache", "redisPort", 6379), redisConns: cfg.get("Cache", "redisConnections", 20), redisMaxConns: cfg.get("Cache", "redisMaxConnections", 30), - redisPassword: cfg.get("Cache", "redisPassword", "") + redisPassword: cfg.get("Cache", "redisPassword", ""), + + # Config + hmacKey: cfg.get("Config", "hmacKey", "secretkey"), + base64Media: cfg.get("Config", "base64Media", false), + minTokens: cfg.get("Config", "tokenCount", 10), + enableRss: cfg.get("Config", "enableRSS", true), + enableDebug: cfg.get("Config", "enableDebug", false), + proxy: cfg.get("Config", "proxy", ""), + proxyAuth: cfg.get("Config", "proxyAuth", "") ) return (conf, cfg) diff --git a/src/nitter.nim b/src/nitter.nim index 225d01b..f6b3189 100644 --- a/src/nitter.nim +++ b/src/nitter.nim @@ -1,5 +1,5 @@ # SPDX-License-Identifier: AGPL-3.0-only -import asyncdispatch, strformat +import asyncdispatch, strformat, logging from net import Port from htmlgen import a from os import getEnv @@ -18,8 +18,7 @@ const issuesUrl = "https://github.com/zedeus/nitter/issues" let configPath = getEnv("NITTER_CONF_FILE", "./nitter.conf") let (cfg, fullCfg) = getConfig(configPath) -when defined(release): - import logging +if not cfg.enableDebug: # Silence Jester's query warning addHandler(newConsoleLogger()) setLogFilter(lvlError) diff --git a/src/types.nim b/src/types.nim index 2dd74e4..56f54dc 100644 --- a/src/types.nim +++ b/src/types.nim @@ -217,6 +217,7 @@ type base64Media*: bool minTokens*: int enableRss*: bool + enableDebug*: bool proxy*: string proxyAuth*: string