"""The logger configuration"""

import logging
from logging import config as log_config

from server import config

cnf = config.get_app_config()


LOGGING_CONFIG = {
    "version": 1,
    "disable_existing_loggers": True,
    "formatters": {
        "standard": {
            "use_colors": True,
            "format": "%(filename)s:%(lineno)d -> %(asctime)s [%(levelname)s]: %(message)s",
        },
        "uvicorn_default": {
            "()": "uvicorn.logging.DefaultFormatter",
            "format": "%(levelprefix)s %(message)s",
            "use_colors": True,
        },
        "uvicorn_access": {
            "()": "uvicorn.logging.AccessFormatter",
            "format": '%(levelprefix)s %(client_addr)s - "%(request_line)s" %(status_code)s',  # noqa: E501
        },
    },
    "handlers": {
        "default": {
            "level": cnf.log_level,
            "formatter": "standard",
            "class": "logging.StreamHandler",
            "stream": "ext://sys.stdout",
        },
        # "sentry": {
        #     "level": "ERROR",
        #     "class": "sentry_sdk.integrations.logging.EventHandler",
        # },
        "uvicorn_default": {
            "level": "INFO",
            "formatter": "uvicorn_default",
            "class": "logging.StreamHandler",
            "stream": "ext://sys.stdout",
        },
        "uvicorn_access": {
            "level": "INFO",
            "formatter": "uvicorn_access",
            "class": "logging.StreamHandler",
            "stream": "ext://sys.stdout",
        },
    },
    "loggers": {
        "": {"handlers": ["default"], "level": cnf.log_level, "propagate": False},
        "uvicorn.access": {
            "handlers": ["uvicorn_access"],
            "level": "INFO",
            "propagate": False,
        },
        "uvicorn.error": {
            "handlers": ["uvicorn_default"],
            "level": "INFO",
            "propagate": False,
        },
        "uvicorn.asgi": {
            "handlers": ["uvicorn_default"],
            "level": "INFO",
            "propagate": False,
        },
    },
}


def get_logger() -> logging.Logger:
    log_config.dictConfig(LOGGING_CONFIG)
    return logging.getLogger()
