diff --git a/.env.example b/.env.example index f3f2b77d..0137f01e 100644 --- a/.env.example +++ b/.env.example @@ -32,3 +32,7 @@ ONION_URL=".onion" RELAYS="wss://relay.routstr.com,wss://relay.nostr.band" CASHU_MINTS="https://mint.minibits.cash/Bitcoin,https://mint.cubabitcoin.org" + +# Development +# DEBUG=TRUE +# LOG_LEVEL=TRACE diff --git a/router/core/logging.py b/router/core/logging.py index 7f7c0b2c..b6217cc9 100644 --- a/router/core/logging.py +++ b/router/core/logging.py @@ -10,6 +10,20 @@ from typing import Any from pythonjsonlogger import jsonlogger from rich.logging import RichHandler +# Define custom TRACE level +TRACE_LEVEL = 5 +logging.addLevelName(TRACE_LEVEL, "TRACE") + + +def trace(self: logging.Logger, message: str, *args: Any, **kwargs: Any) -> None: + """Log with TRACE level""" + if self.isEnabledFor(TRACE_LEVEL): + self._log(TRACE_LEVEL, message, args, **kwargs) + + +# Add the trace method to Logger class +setattr(logging.Logger, "trace", trace) + class DailyRotatingFileHandler(logging.handlers.TimedRotatingFileHandler): """Custom TimedRotatingFileHandler that creates date-based filenames.""" @@ -150,7 +164,12 @@ class SecurityFilter(logging.Filter): def get_log_level() -> str: """Get log level from environment variable.""" - return os.environ.get("LOG_LEVEL", "INFO").upper() + level = os.environ.get("LOG_LEVEL", "INFO").upper() + # Validate log level - if invalid, default to INFO + valid_levels = {"TRACE", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"} + if level not in valid_levels: + level = "INFO" + return level def should_enable_console_logging() -> bool: