Skip to content

Non-blocking logging #708

Description

@ecs-jnguyen

Hi with the python standard logging library, we are able to setup a queue and a listener so that logs are non blocking. Are we able to setup something similar with structlog?

Example from the standard logging library docs:

que = queue.Queue(-1)  # no limit on size
queue_handler = QueueHandler(que)
handler = logging.StreamHandler()
listener = QueueListener(que, handler)
root = logging.getLogger()
root.addHandler(queue_handler)
formatter = logging.Formatter('%(threadName)s: %(message)s')
handler.setFormatter(formatter)
listener.start()
# The log output will display the thread which generated
# the event (the main thread) rather than the internal
# thread which monitors the internal queue. This is what
# you want to happen.
root.warning('Look out!')
listener.stop()

Python standard logging library reference:
https://docs.python.org/3/howto/logging-cookbook.html#dealing-with-handlers-that-block

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions