Logging Rethought 2: The Actions of Frank Taylor Jr. (DjangoCon Europe 2019)

Cd7648c536b4dbe940246b74044fbc52?s=47 Markus H
April 10, 2019

Logging Rethought 2: The Actions of Frank Taylor Jr. (DjangoCon Europe 2019)

My talk from DjangoCon Europe 2019

A writeup of the talk is available at https://markusholtermann.eu/2019/04/logging-rethought/

Cd7648c536b4dbe940246b74044fbc52?s=128

Markus H

April 10, 2019
Tweet

Transcript

  1. 1.

    @m_holtermann Logging Rethought 2 The Actions of Frank Taylor Jr.

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

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

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

    @m_holtermann 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.

    @m_holtermann 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