How to use the structlog.stdlib.add_logger_name function in structlog

To help you get started, we’ve selected a few structlog examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pypa / warehouse / tests / unit / test_logging.py View on Github external
"class": "raven.handlers.logging.SentryHandler",
                        "level": "ERROR",
                        "release": None,
                        "dsn": None,
                        "transport": None,
                    },
                },
                "root": {"level": expected_level, "handlers": ["primary", "sentry"]},
            }
        )
    ]
    assert configure.calls == [
        pretend.call(
            processors=[
                structlog.stdlib.filter_by_level,
                structlog.stdlib.add_logger_name,
                structlog.stdlib.add_log_level,
                mock.ANY,
                mock.ANY,
                structlog.processors.format_exc_info,
                wlogging.RENDERER,
            ],
            logger_factory=mock.ANY,
            wrapper_class=structlog.stdlib.BoundLogger,
            cache_logger_on_first_use=True,
        )
    ]
    assert isinstance(
        configure.calls[0].kwargs["processors"][3],
        structlog.stdlib.PositionalArgumentsFormatter,
    )
    assert isinstance(
github jrobichaud / django-structlog / django_structlog_demo_project / taskapp / celery.py View on Github external
def receiver_setup_logging(
    loglevel, logfile, format, colorize, **kwargs
):  # pragma: no cover
    logging.config.dictConfig(settings.LOGGING)

    structlog.configure(
        processors=[
            structlog.stdlib.filter_by_level,
            structlog.processors.TimeStamper(fmt="iso"),
            structlog.stdlib.add_logger_name,
            structlog.stdlib.add_log_level,
            structlog.stdlib.PositionalArgumentsFormatter(),
            structlog.processors.StackInfoRenderer(),
            structlog.processors.format_exc_info,
            structlog.processors.UnicodeDecoder(),
            structlog.processors.ExceptionPrettyPrinter(),
            # structlog.processors.KeyValueRenderer(),
            structlog.stdlib.ProcessorFormatter.wrap_for_formatter,
        ],
        context_class=structlog.threadlocal.wrap_dict(dict),
        logger_factory=structlog.stdlib.LoggerFactory(),
        wrapper_class=structlog.stdlib.BoundLogger,
        cache_logger_on_first_use=True,
    )
github vapor-ware / synse-server / synse_server / log.py View on Github external
'stream': sys.stdout,
        },
        'error': {
            'class': 'logging.StreamHandler',
            'stream': sys.stderr,
        },
    },
}

logging.config.dictConfig(logging_config)

structlog.configure(
    processors=[
        contextvars.merge_contextvars,
        structlog.stdlib.filter_by_level,
        structlog.stdlib.add_logger_name,
        structlog.stdlib.add_log_level,
        structlog.stdlib.PositionalArgumentsFormatter(),
        structlog.processors.TimeStamper(fmt='iso'),
        structlog.processors.StackInfoRenderer(),
        structlog.processors.format_exc_info,
        structlog.processors.UnicodeDecoder(),
        structlog.processors.KeyValueRenderer(
            key_order=['timestamp', 'logger', 'level', 'event']
        ),
    ],
    context_class=dict,
    logger_factory=structlog.stdlib.LoggerFactory(),
    wrapper_class=structlog.stdlib.BoundLogger,
    cache_logger_on_first_use=True,
)
github miracle2k / k8s-snapshots / k8s_snapshots / logconf.py View on Github external
renderer = structlog.dev.ConsoleRenderer()  # <===
    else:
        # Make it so that 0 ⇒ None
        indent = json_indent or None
        renderer = structlog.processors.JSONRenderer(
            indent=indent,
            serializer=serialize.dumps
        )

    foreign_pre_chain = [
        # Add the log level and a timestamp to the event_dict if the log entry
        # is not from structlog.
        structlog.processors.StackInfoRenderer(),
        structlog.processors.format_exc_info,
        structlog.stdlib.add_log_level,
        structlog.stdlib.add_logger_name,
        foreign_event_to_message,
        rename_level_to_severity,
        timestamper,
    ]

    if level_name == 'DEBUG':
        root_logger_level = 'DEBUG'
    else:
        root_logger_level = 'ERROR'

    logging_config = {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'structlog': {
                '()': structlog.stdlib.ProcessorFormatter,
github ansible / ansible-container / container / visibility.py View on Github external
def getLogger(name):
    return wrap_logger(
        logging.getLogger(name),
        processors=[
            PositionalArgumentsFormatter(),
            filter_by_level,
            add_logger_name,
            add_caller_info,
            #local_var_info,
            unorder_dict,
            TimeStamper(fmt="ISO", utc=False),
            format_exc_info,
            alternate_dev_formatter()
        ],
        wrapper_class=BoundLogger,
    )
github raiden-network / raiden / raiden / log_config.py View on Github external
log_json: bool = False,
    log_file: str = None,
    disable_debug_logfile: bool = False,
    debug_log_file_name: str = None,
    cache_logger_on_first_use: bool = True,
    _first_party_packages: FrozenSet[str] = _FIRST_PARTY_PACKAGES,
    _debug_log_file_additional_level_filters: Dict[str, str] = None,
) -> None:
    structlog.reset_defaults()

    logger_level_config = logger_level_config or dict()
    logger_level_config.setdefault("filelock", "ERROR")
    logger_level_config.setdefault("", DEFAULT_LOG_LEVEL)

    processors = [
        structlog.stdlib.add_logger_name,
        structlog.stdlib.add_log_level,
        add_greenlet_name,
        structlog.stdlib.PositionalArgumentsFormatter(),
        structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S.%f"),
        structlog.processors.StackInfoRenderer(),
        structlog.processors.format_exc_info,
    ]

    if log_json:
        formatter = "json"
    elif colorize and not log_file:
        formatter = "colorized"
    else:
        formatter = "plain"

    redact = redactor(LOG_BLACKLIST)
github pioneers / PieCentral / runtime / runtime / log.py View on Github external
def get_processors(*extra_processors, pretty: bool = True):
    processors = [
        structlog.stdlib.filter_by_level,
        structlog.stdlib.add_logger_name,
        structlog.stdlib.add_log_level,
        structlog.stdlib.PositionalArgumentsFormatter(),
        structlog.processors.TimeStamper(fmt='iso'),
        structlog.processors.StackInfoRenderer(),
        structlog.processors.format_exc_info,
        structlog.processors.UnicodeDecoder(),
        *extra_processors,
    ]

    if pretty:
        renderer = structlog.dev.ConsoleRenderer(pad_event=40)
    else:
        renderer = structlog.processors.JSONRenderer(rapidjson.dumps)
    processors.append(renderer)
    return processors
github Flowminder / FlowKit / flowmachine / flowmachine / core / server / server.py View on Github external
from flowmachine.core import connect
from .query_proxy import (
    QueryProxy,
    MissingQueryError,
    QueryProxyError,
    construct_query_object,
    InvalidGeographyError,
)
from .zmq_interface import ZMQMultipartMessage, ZMQInterfaceError

import structlog

structlog.configure(
    processors=[
        structlog.stdlib.filter_by_level,
        structlog.stdlib.add_logger_name,
        structlog.stdlib.add_log_level,
        structlog.stdlib.PositionalArgumentsFormatter(),
        structlog.processors.TimeStamper(fmt="iso"),
        structlog.processors.StackInfoRenderer(),
        structlog.processors.format_exc_info,
        structlog.processors.JSONRenderer(),
    ],
    context_class=dict,
    logger_factory=structlog.stdlib.LoggerFactory(),
    wrapper_class=structlog.stdlib.BoundLogger,
    cache_logger_on_first_use=True,
)

logger = logging.getLogger("flowmachine").getChild(__name__)
# Logger for all queries run or accessed
query_run_log = logging.getLogger("flowmachine-server")
github wimglenn / johnnydep / johnnydep / logs.py View on Github external
#     "formatter": "plain",
                # },
            },
            "loggers": {
                "": {
                    "handlers": ["default"],
                    # "handlers": ["default", "file"],
                    "level": "DEBUG",
                    "propagate": True,
                }
            },
        }
    )
    structlog.configure(
        processors=[
            structlog.stdlib.add_logger_name,
            structlog.stdlib.add_log_level,
            structlog.stdlib.PositionalArgumentsFormatter(),
            timestamper,
            structlog.processors.StackInfoRenderer(),
            structlog.processors.format_exc_info,
            structlog.stdlib.ProcessorFormatter.wrap_for_formatter,
        ],
        context_class=dict,
        logger_factory=structlog.stdlib.LoggerFactory(),
        wrapper_class=structlog.stdlib.BoundLogger,
        cache_logger_on_first_use=True,
    )
github wgaggioli / elk-example / webapp / settings.py View on Github external
'warn': 'WARNING',
    'warning': 'WARNING',
    'info': 'INFO',
    'debug': 'DEBUG',
    'notset': 'NOTSET',
}


def add_log_level(logger, method_name, event_dict):
    event_dict['level'] = _METHOD_TO_NAME[method_name]
    return event_dict


STRUCTLOG_PROCESSORS = [
    structlog.stdlib.filter_by_level,
    structlog.stdlib.add_logger_name,
    add_log_level,
    structlog.stdlib.PositionalArgumentsFormatter(),
    structlog.processors.TimeStamper(fmt='iso', key='@timestamp'),
    structlog.processors.StackInfoRenderer(),
    structlog.processors.format_exc_info,
    structlog.processors.JSONRenderer(),
]