Logging Rethought 2: The Actions of Frank Taylor Jr. (PyCon UK 2019)

Cd7648c536b4dbe940246b74044fbc52?s=47 Markus H
September 13, 2019

Logging Rethought 2: The Actions of Frank Taylor Jr. (PyCon UK 2019)

My talk from PyCon UK 2019

A write-up of my talk is available at https://markusholtermann.eu/2019/04/logging-rethought/

Cd7648c536b4dbe940246b74044fbc52?s=128

Markus H

September 13, 2019
Tweet

Transcript

  1. 1.

    Logging Rethought 2 The Actions of Frank Taylor Jr. markusholtermann.eu

    • gitlab.com/MarkusH • github.com/MarkusH • @m_holtermann
  2. 5.

    import logging logger = logging.getLogger(__name__) logger.error( "Login failed because the

    " "connection to the authentication " "provider %s timed out.", provider_name )
  3. 22.

    import uuid, structlog logger = structlog.get_logger("structlog") def structlog_middleware(get_response): def _inner(request):

    request.trace_id = ( request.META.get("HTTP_X_TRACE_ID") or str(uuid.uuid4()) ) log = logger.new(trace_id=request.trace_id) return get_response(request) return _inner
  4. 23.

    import structlog logger = structlog.get_logger("structlog") def structlog_user_middleware(get_response): def _inner(request): if

    request.user.is_authenticated: logger.bind(user_id=request.user.pk) return get_response(request) return _inner