Skip to content

Instantly share code, notes, and snippets.

@YakBarber
Created February 28, 2018 01:51
Show Gist options
  • Save YakBarber/82afbec945105418cf88204f8f78ab95 to your computer and use it in GitHub Desktop.
Save YakBarber/82afbec945105418cf88204f8f78ab95 to your computer and use it in GitHub Desktop.
Prevent werkzeug from overriding your own logging handlers
#Werkzeug only checks the root logger for user-created handlers before setting its own.
#Since the correct way to create module-wide logging is _not_ with the root logger, this
#causes werkzeug to set its own logger over top of any you may create.
#This can be solved by setting the level of the 'werkzeug' logger to > 0 before werkzeug
#is started. It can also be solved by adding a handler to the root logger. But the consensus
#is that you should not do that. Do this:
import logging
#somewhere before app.run
wlog = logging.getLogger("werkzeug")
wlog.setLevel(logging.DEBUG) #anything other than logging.NOTSET
wlog.addHandler(your_handler)
wlog.addHandler(your_other_handler)
#whatever else
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment