Skip to content

Instantly share code, notes, and snippets.

@sakku116
Created March 8, 2023 03:17
Show Gist options
  • Save sakku116/a7d5fc851452f141a297abb6e77a4b6a to your computer and use it in GitHub Desktop.
Save sakku116/a7d5fc851452f141a297abb6e77a4b6a to your computer and use it in GitHub Desktop.
from uvicorn.config import LOGGING_CONFIG
import logging
# custom logging
LOGGING_CONFIG["loggers"]["uvicorn.custom"] = {
"handlers": ["custom"],
"level": "INFO",
"propagate": False
}
LOGGING_CONFIG["handlers"]["custom"] = {
"formatter": "custom",
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout",
}
LOGGING_CONFIG["formatters"]["custom"] = {
"()": "uvicorn.logging.ColourizedFormatter",
"fmt": "%(asctime)s %(levelprefix)s [%(filename)s:%(lineno)d] - %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S"
}
# call the logger
logger = logging.getLogger("uvicorn.custom")
logger.info("hello world)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment