Elegant setup of Python logging in Django

前端 未结 4 778
别那么骄傲
别那么骄傲 2020-11-28 18:00

I have yet to find a way of setting up Python logging with Django that I\'m happy with. My requirements are fairly simple:

  • Different log handlers for different
4条回答
  •  自闭症患者
    2020-11-28 18:11

    We initialize logging in the top-level urls.py by using a logging.ini file.

    The location of the logging.ini is provided in settings.py, but that's all.

    Each module then does

    logger = logging.getLogger(__name__)
    

    To distinguish testing, development and production instances, we have different logging.ini files. For the most part, we have a "console log" that goes to stderr with Errors only. We have an "application log" that uses a regular rolling log file that goes to a logs directory.

提交回复
热议问题