Skip to content

Commit

Permalink
Add color settings, restore enable_access_log setting effectiveness
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 committed Jun 17, 2024
1 parent ec9a69e commit 5a36f31
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/edge_proxy/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ def setup_logging(settings: LoggingSettings) -> None:
cache_logger_on_first_use=True,
)

# Propagate uvicorn logs instead of letting uvicorn configure the format
for name in ["uvicorn", "uvicorn.error"]:
logging.getLogger(name).handlers.clear()
logging.getLogger(name).propagate = True

logging.getLogger("uvicorn.access").handlers.clear()
logging.getLogger("uvicorn.access").propagate = settings.enable_access_log

override = settings.override
logging.config.dictConfig(
{
Expand All @@ -77,7 +85,8 @@ def setup_logging(settings: LoggingSettings) -> None:
"processors": [
structlog.stdlib.ProcessorFormatter.remove_processors_meta,
structlog.dev.ConsoleRenderer(
event_key=settings.log_event_field_name, colors=True
event_key=settings.log_event_field_name,
colors=settings.colors,
),
],
"foreign_pre_chain": processors,
Expand Down Expand Up @@ -108,13 +117,6 @@ def setup_logging(settings: LoggingSettings) -> None:
"level": settings.log_level.to_logging_log_level(),
"propagate": True,
},
"uvicorn.access": {
"handlers": ["default"],
"disabled": not settings.enable_access_log,
},
"uvicorn.error": {
"handlers": ["default"],
},
**(override.get("loggers") or {}),
},
}
Expand Down
1 change: 1 addition & 0 deletions src/edge_proxy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def serve():
host=str(settings.server.host),
port=settings.server.port,
reload=settings.server.reload,
use_colors=settings.logging.colors,
)


Expand Down
1 change: 1 addition & 0 deletions src/edge_proxy/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class LoggingSettings(BaseModel):
log_format: LogFormat = LogFormat.GENERIC
log_level: LogLevel = LogLevel.INFO
log_event_field_name: str = "message"
colors: bool = True
override: dict[str, Any] = Field(default_factory=dict)


Expand Down

0 comments on commit 5a36f31

Please sign in to comment.