Skip to content

Commit

Permalink
Update log format to follow the Safe guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
falvaradorodriguez committed Aug 7, 2024
1 parent 615435c commit db61d99
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Base settings file for FastApi application.
"""

import json
import logging.config
import os

from pydantic_settings import BaseSettings, SettingsConfigDict
Expand All @@ -19,6 +21,41 @@ class Settings(BaseSettings):
DEFAULT_SIWE_MESSAGE_STATEMENT: str = (
"Welcome to Safe! I accept the Terms of Use: https://safe.global/terms."
)
LOG_LEVEL: str = "INFO"


settings = Settings()


LOG_FORMAT = {
"level": "%(levelname)s",
"timestamp": "%(asctime)s",
"message": "%(message)s",
"context": "",
"messageContext": "",
}

LOG_CONFIG = {
"version": 1,
"disable_existing_loggers": True,
"formatters": {"default": {"format": json.dumps(LOG_FORMAT)}},
"handlers": {
"console": {
"formatter": "default",
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout",
"level": settings.LOG_LEVEL,
}
},
"root": {"handlers": ["console"], "level": settings.LOG_LEVEL},
"loggers": {
"gunicorn": {"propagate": True},
"gunicorn.access": {"propagate": True},
"gunicorn.error": {"propagate": True},
"uvicorn": {"propagate": True},
"uvicorn.access": {"propagate": True},
"uvicorn.error": {"propagate": True},
},
}

logging.config.dictConfig(LOG_CONFIG)

0 comments on commit db61d99

Please sign in to comment.