Skip to content
Snippets Groups Projects
config.py 1.1 KiB
Newer Older
  • Learn to ignore specific revisions
  • istmxrein's avatar
    istmxrein committed
    import logging
    
    from typing import Dict
    
    from pydantic import BaseModel
    
    LOG_LEVEL = os.getenv('LOG_LEVEL') or 'INFO'
    
    istmxrein's avatar
    istmxrein committed
    
    
    class LogConfig(BaseModel):
        """Logging configuration to be set for the server"""
    
        LOG_FORMAT: str = "%(levelprefix)s | %(asctime)s | %(message)s"
        LOG_LEVEL: str = LOG_LEVEL
    
        # Logging config
    
        version: int = 1
        disable_existing_loggers: bool = False
        formatters: Dict = {
    
    istmxrein's avatar
    istmxrein committed
            "default": {
                "()": "uvicorn.logging.DefaultFormatter",
                "fmt": LOG_FORMAT,
                "datefmt": "%Y-%m-%d %H:%M:%S",
            },
        }
    
    istmxrein's avatar
    istmxrein committed
            "default": {
                "formatter": "default",
                "class": "logging.StreamHandler",
                "stream": "ext://sys.stderr",
            },
        }
    
    istmxrein's avatar
    istmxrein committed
            '': {"handlers": ["default"], "level": LOG_LEVEL, 'propagate': False},
            'uvicorn': {"handlers": ["default"], "level": LOG_LEVEL, 'propagate': False}
        }
    
    
    class EndpointFilter(logging.Filter):
        def filter(self, record: logging.LogRecord) -> bool:
            return record.getMessage().find("/health") == -1