Python flask.logging.default_handler() Examples

The following are 3 code examples of flask.logging.default_handler(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask.logging , or try the search function .
Example #1
Source File: brotab_mediator.py    From brotab with MIT License 5 votes vote down vote up
def run_mediator(port: int, remote_api, no_logging=False):
    global browser
    # reassign this variable again so that tests could mock it
    browser = remote_api
    # TODO: does not really work, I still see logs in unittests
    if no_logging:
        log = logging.getLogger('werkzeug')
        log.setLevel(logging.ERROR)
        log.disabled = True
        app.logger.disabled = True
        from flask.logging import default_handler
        app.logger.removeHandler(default_handler)
    return app.run(DEFAULT_HTTP_IFACE, port, debug=False, threaded=False) 
Example #2
Source File: FlaskServer.py    From BAC0 with GNU Lesser General Public License v3.0 5 votes vote down vote up
def startServer(self):
        self.flask_app.run(port=self.port, host="0.0.0.0")
        self.flask_app.logger.removeHandler(default_handler) 
Example #3
Source File: main.py    From ctfscoreboard with Apache License 2.0 4 votes vote down vote up
def setup_logging(app):
    log_formatter = logger.Formatter(
            '%(asctime)s %(levelname)8s [%(filename)s:%(lineno)d] '
            '%(client)s %(message)s')
    # log to files unless on AppEngine
    if not on_appengine():
        # Main logger
        if not (app.debug or app.config.get('TESTING')):
            handler = logging.FileHandler(
                app.config.get('LOGFILE', '/tmp/scoreboard.wsgi.log'))
            handler.setLevel(logging.INFO)
            handler.setFormatter(log_formatter)
            app.logger.addHandler(handler)
        else:
            app.logger.handlers[0].setFormatter(log_formatter)

        # Challenge logger
        handler = logging.FileHandler(
            app.config.get('CHALLENGELOG', '/tmp/scoreboard.challenge.log'))
        handler.setLevel(logging.INFO)
        handler.setFormatter(logger.Formatter(
            '%(asctime)s %(client)s %(message)s'))
        local_logger = logging.getLogger('scoreboard')
        local_logger.addHandler(handler)
        app.challenge_log = local_logger
    else:
        app.challenge_log = app.logger
        try:
            import google.cloud.logging
            from google.cloud.logging import handlers
            client = google.cloud.logging.Client()
            client.setup_logging()
            handler = handlers.CloudLoggingHandler(client)
            app.logger.addHandler(handler)
            handler.setLevel(logging.INFO)
            return app
        except ImportError as ex:
            logging.error('Failed setting up logging: %s', ex)
        if not app.logger.handlers:
            app.logger.addHandler(flask_logging.default_handler)
            app.logger.handlers[0].setFormatter(log_formatter)
            logging.getLogger().handlers[0].setFormatter(log_formatter)

    return app