Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make --quiet more quiet #308

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions grip/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import threading
import time
import errno
import contextlib
from traceback import format_exc
try:
from urlparse import urlparse
Expand Down Expand Up @@ -109,8 +110,10 @@ def __init__(self, source=None, auth=None, renderer=None,
self.quiet = quiet
if self.quiet:
import logging
# Disable werkzeug and flask logging
self.logger.setLevel(logging.CRITICAL)
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
log.setLevel(logging.CRITICAL)

# Overridable attributes
if self.renderer is None:
Expand Down Expand Up @@ -434,10 +437,19 @@ def run(self, host=None, port=None, debug=None, use_reloader=None,
start_browser_when_ready(host, port, self._shutdown_event)
if open_browser else None)

# Run local server
super(Grip, self).run(host, port, debug=debug,
use_reloader=use_reloader,
threaded=True)
# Redirect stdout if requred
output_file = sys.stdout
if self.quiet:
output_file = open(os.devnull, 'w')

with contextlib.redirect_stdout(output_file):
# Run local server
super(Grip, self).run(host, port, debug=debug,
use_reloader=use_reloader,
threaded=True)

if output_file != sys.stdout:
output_file.close()

# Signal to the polling and browser threads that they should exit
if not self.quiet:
Expand Down