logger.py 755 B

123456789101112131415161718192021222324252627282930
  1. import logging
  2. from logging.config import dictConfig
  3. def setup_logging(app):
  4. """Configure basic logging for the application."""
  5. level = logging.DEBUG if app.config.get("DEBUG") else logging.INFO
  6. config = {
  7. "version": 1,
  8. "disable_existing_loggers": False,
  9. "formatters": {
  10. "default": {
  11. "format": "%(asctime)s %(levelname)s %(name)s: %(message)s",
  12. }
  13. },
  14. "handlers": {
  15. "console": {
  16. "class": "logging.StreamHandler",
  17. "formatter": "default",
  18. "level": level,
  19. }
  20. },
  21. "root": {
  22. "handlers": ["console"],
  23. "level": level,
  24. },
  25. }
  26. dictConfig(config)