From e71b307a38d4542ea83295c2108d3db899f61e90 Mon Sep 17 00:00:00 2001 From: jerryfletcher21 Date: Wed, 14 May 2025 16:37:35 +0200 Subject: [PATCH 1/5] 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"), }, }, } From e81c1fb3d42ae19c1ffde1136424214a6c5b2401 Mon Sep 17 00:00:00 2001 From: jerryfletcher21 Date: Fri, 16 May 2025 18:17:12 +0200 Subject: [PATCH 2/5] read LOG_TO_CONSOLE with decouple --- robosats/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robosats/settings.py b/robosats/settings.py index af72c48c..80a8f1dd 100644 --- a/robosats/settings.py +++ b/robosats/settings.py @@ -59,7 +59,7 @@ CORS_ALLOW_ALL_ORIGINS = True SESSION_COOKIE_HTTPONLY = False # Logging settings -if os.environ.get("LOG_TO_CONSOLE"): +if config("LOG_TO_CONSOLE", cast=bool, default=False): LOGGING = { "version": 1, "disable_existing_loggers": False, From f9028c287a51dfec1161d8ac8dc423af311171f8 Mon Sep 17 00:00:00 2001 From: jerryfletcher21 Date: Fri, 16 May 2025 18:24:29 +0200 Subject: [PATCH 3/5] remove os import --- robosats/settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/robosats/settings.py b/robosats/settings.py index 80a8f1dd..093aad06 100644 --- a/robosats/settings.py +++ b/robosats/settings.py @@ -12,7 +12,6 @@ https://docs.djangoproject.com/en/4.0/ref/settings/ """ import json -import os import textwrap from pathlib import Path From a717151b5006dffc1857919fd4ba8cf968ae34d8 Mon Sep 17 00:00:00 2001 From: jerryfletcher21 Date: Fri, 16 May 2025 18:36:13 +0200 Subject: [PATCH 4/5] document LOG_TO_CONSOLE in .env-sample --- .env-sample | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.env-sample b/.env-sample index e4df1368..44a66072 100644 --- a/.env-sample +++ b/.env-sample @@ -42,7 +42,9 @@ LND_GRPC_HOST='localhost:10009' REDIS_URL='redis://localhost:6379/1' -# If set, log to file specified +# If set to True, load to console (default is False) +# LOG_TO_CONSOLE=False +# If set, log to file specified (LOG_TO_CONSOLE should be False) # LOG_FILE="" # Change logger level (default is "WARNING") # LOGGER_LEVEL="WARNING" From b44866b36e6f89fc1fe4b8d3d85b0e8af4326e40 Mon Sep 17 00:00:00 2001 From: jerryfletcher21 Date: Tue, 20 May 2025 20:59:41 +0200 Subject: [PATCH 5/5] document LOG_TO_CONSOLE to True in .env-sample --- .env-sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env-sample b/.env-sample index 44a66072..64b12a5a 100644 --- a/.env-sample +++ b/.env-sample @@ -43,7 +43,7 @@ LND_GRPC_HOST='localhost:10009' REDIS_URL='redis://localhost:6379/1' # If set to True, load to console (default is False) -# LOG_TO_CONSOLE=False +# LOG_TO_CONSOLE=True # If set, log to file specified (LOG_TO_CONSOLE should be False) # LOG_FILE="" # Change logger level (default is "WARNING")