diff --git a/.env-sample b/.env-sample index 1b44b63e..64b12a5a 100644 --- a/.env-sample +++ b/.env-sample @@ -42,6 +42,13 @@ LND_GRPC_HOST='localhost:10009' REDIS_URL='redis://localhost:6379/1' +# If set to True, load to console (default is 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") +# 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..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 @@ -59,7 +58,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, @@ -70,12 +69,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"), }, }, }