Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion hypertrade/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from starlette.middleware.trustedhost import TrustedHostMiddleware

from .config import get_settings
from .logging import log_startup_banner, log_endpoints
from .logging import log_startup_banner, log_endpoints, configure_logging
from .middleware.logging import LoggingMiddleware
from .middleware.content_limit import ContentLengthLimitMiddleware
from .middleware.rate_limit import RateLimitMiddleware
Expand Down Expand Up @@ -104,6 +104,9 @@ def create_daemon() -> FastAPI:
except ValidationError:
_please_die_gracefully()

# Configure logging based on settings
configure_logging(settings.log_level)

app.state.settings = settings

# Pre-bind optional Telegram notifier to avoid per-request env access
Expand Down
17 changes: 17 additions & 0 deletions hypertrade/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@
# Use uvicorn.error logger (guaranteed to exist + colored in dev)
log = pylog.getLogger("uvicorn.error")


def configure_logging(log_level: str = "INFO") -> None:
"""Configure Python logging to use the specified level."""
level = log_level.upper()
valid_levels = {"CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NOTSET"}

if level not in valid_levels:
level = "INFO"

Comment on lines +20 to +24
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation logic here is redundant. The log_level parameter is already validated and normalized by the _normalize_level field validator in hypertrade/config.py (lines 94-99), which ensures that only valid log levels reach this function. This duplicate validation adds unnecessary complexity. Consider removing lines 19-23 and using log_level directly, or at minimum, just call .upper() without re-validation.

Suggested change
valid_levels = {"CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NOTSET"}
if level not in valid_levels:
level = "INFO"

Copilot uses AI. Check for mistakes.
# Configure uvicorn loggers
pylog.getLogger("uvicorn").setLevel(level)
pylog.getLogger("uvicorn.access").setLevel(level)
pylog.getLogger("uvicorn.error").setLevel(level)

# Configure app logger
pylog.getLogger("hypertrade").setLevel(level)
Comment on lines +17 to +31
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new configure_logging function lacks test coverage. The repository has comprehensive tests for other modules (e.g., test_health.py, test_webhook.py), but this new logging configuration functionality is not tested. Consider adding tests to verify:

  • Correct log level configuration for all uvicorn and app loggers
  • Behavior with valid and invalid log levels
  • Integration with the daemon initialization

Copilot uses AI. Check for mistakes.

# pylint: disable=too-few-public-methods
class _MessageFilter(pylog.Filter):
def __init__(self, *, deny_contains: Optional[List[str]] = None):
Expand Down