Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Logging Rethought 2: The Actions of Frank Taylo...

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/

Markus H

April 10, 2019
Tweet

More Decks by Markus H

Other Decks in Technology

Transcript

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

    markusholtermann.eu • gitlab.com/MarkusH • github.com/MarkusH • @m_holtermann
  2. @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. @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. @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