From e71b307a38d4542ea83295c2108d3db899f61e90 Mon Sep 17 00:00:00 2001 From: jerryfletcher21 Date: Wed, 14 May 2025 16:37:35 +0200 Subject: [PATCH] allow logging to file and setting LOGGER_LEVEL --- .env-sample | 5 +++++ robosats/settings.py | 25 +++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/.env-sample b/.env-sample index 1b44b63e..e4df1368 100644 --- a/.env-sample +++ b/.env-sample @@ -42,6 +42,11 @@ LND_GRPC_HOST='localhost:10009' REDIS_URL='redis://localhost:6379/1' +# If set, log to file specified +# LOG_FILE="" +# Change logger level (default is "WARNING") +# LOGGER_LEVEL="WARNING" + # List of market price public APIs. If the currency is available in more than 1 API, will use median price. MARKET_PRICE_APIS = https://blockchain.info/ticker, https://api.yadio.io/exrates/BTC, https://bitpay.com/rates/BTC, https://criptoya.com/api/btc diff --git a/robosats/settings.py b/robosats/settings.py index f2a92677..af72c48c 100644 --- a/robosats/settings.py +++ b/robosats/settings.py @@ -70,12 +70,33 @@ if os.environ.get("LOG_TO_CONSOLE"): }, "root": { "handlers": ["console"], - "level": "WARNING", + "level": config("LOGGER_LEVEL", cast=str, default="WARNING"), }, "loggers": { "api.utils": { "handlers": ["console"], - "level": "WARNING", + "level": config("LOGGER_LEVEL", cast=str, default="WARNING"), + }, + }, + } +elif config("LOG_FILE", False): + LOGGING = { + "version": 1, + "disable_existing_loggers": False, + "handlers": { + "file": { + "class": "logging.FileHandler", + "filename": config("LOG_FILE", cast=str), + }, + }, + "root": { + "handlers": ["file"], + "level": config("LOGGER_LEVEL", cast=str, default="WARNING"), + }, + "loggers": { + "api.utils": { + "handlers": ["file"], + "level": config("LOGGER_LEVEL", cast=str, default="WARNING"), }, }, }