Skip to content

Instantly share code, notes, and snippets.

@daryltucker
Last active October 12, 2023 13:31
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save daryltucker/e40c59a267ea75db12b1 to your computer and use it in GitHub Desktop.
Save daryltucker/e40c59a267ea75db12b1 to your computer and use it in GitHub Desktop.
Really disable logger logging in Flask
# I have my own logging setup and had a hard time disabling console output in Flask.
app.logger.disabled = True
log = logging.getLogger('werkzeug')
log.disabled = True
# New, 2022 Method:
logging.getLogger('werkzeug').disabled = True
@yurisbv
Copy link

yurisbv commented Feb 1, 2018

Nice!

@techdiverdown
Copy link

Great, used this today. Thanks!

@BobDenny
Copy link

BobDenny commented Dec 1, 2018

What is 'cf'?

@tw7613781
Copy link

tw7613781 commented Feb 25, 2019

What is 'cf'?

import logging
app.logger.disabled = True
log = logging.getLogger('werkzeug')
log.disabled = True

@Jonney
Copy link

Jonney commented Feb 18, 2020

It dosn't work fo me

@mail4hafij
Copy link

It doesn't work for me either.

@daryltucker
Copy link
Author

daryltucker commented Nov 21, 2021

This was used back in maybe 2012 and published in 2014. Sorry to any users who are having issues w. it in 2021+ no longer working. If anybody provides an update, I can update the gist. Thanks.

@jorgectf
Copy link

This works for me :)

@manasomali
Copy link

i just add the line "logging.getLogger('werkzeug').disabled = True" and worked

@hungdx6
Copy link

hungdx6 commented May 9, 2022

Thank you, it worked

@mconigliaro
Copy link

For the record, this only disables the logging statements. If you want to disable the console warnings too, you have to monkeypatch the function that does that (see: cs01/gdbgui#425):

import flask.cli    
flask.cli.show_server_banner = lambda *args: None

The old hack (os.environ["WERKZEUG_RUN_MAIN"] = "true") doesn't work in werkzeug >=2.1.0.

@cj-praveen
Copy link

@mconigliaro Man! your code works well! Thanks :)

@NefixEstrada
Copy link

If using flask-socketio:

logging.getLogger("werkzeug").disabled = True
logging.getLogger("geventwebsocket.handler").disabled = True

@tanjuntao
Copy link

tanjuntao commented Jun 26, 2023

Really nice! I'm using Flask 2.2.3, it works.

@miloandrs
Copy link

miloandrs commented Oct 12, 2023

Thank you!
This worked perfectly for me.

pasted right below the instantiation line
app = Flask(name)
logging.getLogger('werkzeug').disabled = True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment