예제 #1
0
def console_log_run(app, port, use_reloader):
    from console_log import ConsoleLog
    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()
예제 #2
0
app = Flask(__name__)

logger = logging.getLogger('console')
logger.setLevel(logging.DEBUG)

with open(__file__) as f:
    source = '<pre>{}</pre>'.format(html.escape(f.read()))


@app.route("/")
def hello():
    logger.error('Error logged from Python')
    logger.warning('Warning logged from Python')
    logger.info('Info logged from Python')
    logger.debug('Debug logged from Python')
    logger.debug({'foo': ['bar', 'baz']})
    return source


app = ConsoleLog(app, logger)


@werkzeug.serving.run_with_reloader
def main():
    server = pywsgi.WSGIServer(("", 5000), app, handler_class=WebSocketHandler)
    server.serve_forever()


if __name__ == '__main__':
    main()