Example #1
0
def apply_json_logger():
    dictConfig({
        "version": 1,
        "formatters": {
            "default": {
                "()": lambda *a, **k: JsonFormatter()
            }
        },
        "filters": {
            "requests": {
                "()": lambda *a, **k: RequestContextFilter()
            }
        },
        "handlers": {
            "wsgi": {
                "class": "logging.StreamHandler",
                "stream": "ext://flask.logging.wsgi_errors_stream",
                "formatter": "default",
                "filters": ["requests"],
            }
        },
        "root": {
            "level": "INFO",
            "handlers": ["wsgi"]
        },
    })
Example #2
0
def logger(log_stream):
    logger = logging.getLogger()
    for handler in logger.handlers:
        logger.removeHandler(handler)

    logHandler = logging.StreamHandler(log_stream)
    formatter = JsonFormatter()
    logHandler.setFormatter(formatter)
    logger.setLevel(logging.INFO)
    logger.addFilter(RequestContextFilter())
    logger.addHandler(logHandler)

    return logger
Example #3
0
def setup_task_logger(*args, **kwargs):
    if app.config.get("LOG_JSON"):
        logger = logging.getLogger()
        for handler in logger.handlers:
            handler.setFormatter(JsonFormatter(source="queue"))