import logging


def setup_gunicorn_logging(app):
    """This is meant to be called if the Flask app is run by Gunicorn.

    The logger will set the handlers of the Flask app logger
    to the Gunicorn logger. The Flask app will have the same
    log level as the Gunicorn logger.

    :param app: the actual Flask app to be logged

    :return: the logger object
    """

    gunicorn_logger = logging.getLogger('gunicorn.error')
    app.logger.handlers = gunicorn_logger.handlers
    app.logger.setLevel(gunicorn_logger.level)
    return app.logger