How do I use Logging in the Django Debug Toolbar?

前端 未结 3 528
别跟我提以往
别跟我提以往 2021-02-02 06:09

I would like to output debug messages in my django app at different points in a view function. The docs for the django-debug-toolbar say it uses the build in python logging but

3条回答
  •  感动是毒
    2021-02-02 07:07

    If you have an existing LOGGING config dict, and you don't want to mess it up by switching to 'incremental', you'll need to re-add the DjDT log as a handler, then add it to the root logger's list of handlers.

    from debug_toolbar.panels.logging import collector # needed for handler constructor below
    LOGGING = {
        # existing options, formatters, loggers, etc
        handlers = {
            # existing handlers
            'djdt_log': {
                'level': 'DEBUG',
                'class': 'debug_toolbar.panels.logging.ThreadTrackingHandler',
                'collector': collector,
            },
        },
        'root': {
            'level': 'DEBUG',
            'handlers': ['djdt_log'],
        },
    }
    

    If there's a cleaner way to do this, I'd love to see it.

提交回复
热议问题