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

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

Markus H
August 03, 2019

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

My talk from PyCon Australia 2019

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

Markus H

August 03, 2019
Tweet

More Decks by Markus H

Other Decks in Technology

Transcript

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

    • gitlab.com/MarkusH • github.com/MarkusH • @m_holtermann
  2. import logging logger = logging.getLogger(__name__) logger.error( "Login failed because the

    " "connection to the authentication " "provider %s timed out.", provider_name )
  3. 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. 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