-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
RFC: add logger that logs into browser console #4702
Changes from 4 commits
563b09a
25e578e
6746d43
d976ab2
1cbb7b3
436d3e8
6834adc
21f6fec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
from flask_migrate import MigrateCommand | ||
from flask_script import Manager | ||
from pathlib2 import Path | ||
import werkzeug.serving | ||
import yaml | ||
|
||
from superset import app, db, dict_import_export_util, security, utils | ||
|
@@ -31,11 +32,45 @@ def init(): | |
security.sync_role_definitions() | ||
|
||
|
||
def debug_run(app, port, use_reloader): | ||
return app.run( | ||
host='0.0.0.0', | ||
port=int(port), | ||
threaded=True, | ||
debug=True, | ||
use_reloader=use_reloader) | ||
|
||
|
||
def console_log_run(app, port, use_reloader): | ||
from console_log import ConsoleLog | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you put these imports at the top There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know imports should be top-level, but these are optional requirements (see the modified |
||
from gevent import pywsgi | ||
from geventwebsocket.handler import WebSocketHandler | ||
|
||
app.wsgi_app = ConsoleLog(app.wsgi_app, app.logger) | ||
|
||
def run(): | ||
server = pywsgi.WSGIServer( | ||
('0.0.0.0', int(port)), | ||
app, | ||
handler_class=WebSocketHandler) | ||
server.serve_forever() | ||
|
||
if use_reloader: | ||
from gevent import monkey | ||
monkey.patch_all() | ||
run = werkzeug.serving.run_with_reloader(run) | ||
|
||
run() | ||
|
||
|
||
@manager.option( | ||
'-d', '--debug', action='store_true', | ||
help='Start the web server in debug mode') | ||
@manager.option( | ||
'-n', '--no-reload', action='store_false', dest='no_reload', | ||
'--console-log', action='store_true', | ||
help='Create logger that logs to the browser console (implies -d)') | ||
@manager.option( | ||
'-n', '--no-reload', action='store_false', dest='use_reloader', | ||
default=config.get('FLASK_USE_RELOAD'), | ||
help="Don't use the reloader in debug mode") | ||
@manager.option( | ||
|
@@ -56,9 +91,9 @@ def init(): | |
help='Path to a UNIX socket as an alternative to address:port, e.g. ' | ||
'/var/run/superset.sock. ' | ||
'Will override the address and port values.') | ||
def runserver(debug, no_reload, address, port, timeout, workers, socket): | ||
def runserver(debug, console_log, use_reloader, address, port, timeout, workers, socket): | ||
"""Starts a Superset web server.""" | ||
debug = debug or config.get('DEBUG') | ||
debug = debug or config.get('DEBUG') or console_log | ||
if debug: | ||
print(Fore.BLUE + '-=' * 20) | ||
print( | ||
|
@@ -67,12 +102,10 @@ def runserver(debug, no_reload, address, port, timeout, workers, socket): | |
Fore.YELLOW + ' mode') | ||
print(Fore.BLUE + '-=' * 20) | ||
print(Style.RESET_ALL) | ||
app.run( | ||
host='0.0.0.0', | ||
port=int(port), | ||
threaded=True, | ||
debug=True, | ||
use_reloader=no_reload) | ||
if console_log: | ||
console_log_run(app, port, use_reloader) | ||
else: | ||
debug_run(app, port, use_reloader) | ||
else: | ||
addr_str = ' unix:{socket} ' if socket else' {address}:{port} ' | ||
cmd = ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -747,8 +747,10 @@ def shortner(self): | |
obj = models.Url(url=url) | ||
db.session.add(obj) | ||
db.session.commit() | ||
return('http://{request.headers[Host]}/{directory}?r={obj.id}'.format( | ||
request=request, directory=directory, obj=obj)) | ||
return Response( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious on the angle here, you prefer an explicit |
||
'http://{request.headers[Host]}/{directory}?r={obj.id}'.format( | ||
request=request, directory=directory, obj=obj), | ||
mimetype='text/plain') | ||
|
||
@expose('/msg/') | ||
def msg(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh does
logging.debug('Foo')
work?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me give it a try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mistercrunch, currently it won't work because
console_log
adds the websocket handler to a single logger instance — Flask uses it's own (flask.app
), and it's different from the root logger. I'll modify the library so that it takes more than one logger instance, should be straightforward.