Skip to main content

Narration is a logging library starting a server receiving log records from other process.

Project description

https://img.shields.io/pypi/v/narration.svg https://img.shields.io/pypi/pyversions/narration.svg https://img.shields.io/pypi/status/narration.svg https://img.shields.io/pypi/l/narration.svg

narration

Logging is easy, but setup is messy and boring in multi processes contexts, due to the various way python can spawn processes (fork, spawn, forkserver) via explicit or implicit spawning context.

Narration handles the following logging setup boiler plate:

  • main process’s logger writes log record emitted by the process itself or its child processes

  • child process’s logger’s handler forward log records to the main process only

Installation

Install python virtual envs needed by tox/IDE

bash make.sh --setup-python-dev-envs
bash make.sh --install-dependencies
bash make.sh --install-tests-dependencies

Usage

  • Create your loggers as you like (eg: logging.basicConfig(…))

  • On the master process, setup the logger to act as server:

import narration
import multiprocessing
import logging

ctx = mutiprocessing.get_context()
m = ctx.Manager()

logger=logging.getLogger()
client_handler_settings = narration.setup_server_handlers(logger=logger, ctx=ctx, ctx_manager=m)
logger.debug("Main process ready")

pool = multiprocessing.pool.Pool(10, child_process_worker_function, [client_handler_settings] , 2, ctx)
  • On the child process, setup the logger to act as ‘emitting’ client:

import narration
import multiprocessing
import logging

# Child process must receive the 'client_handler_settings' payload when starting the process

# Re-create a logger, replacing handlers/formatting (if any) with handler to forrward records to the master process
logger=logging.getLogger()
narration.setup_client_handlers(logger=logger, handler_name_to_client_handler_settings=client_handler_settings)
logger.debug("Child process ready")
  • Child process log records will be sent to the master process’s logger’s original handlers for procesing.

Main process ready
Child process ready

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

narration-0.2.16.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

narration-0.2.16-py2.py3-none-any.whl (44.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file narration-0.2.16.tar.gz.

File metadata

  • Download URL: narration-0.2.16.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for narration-0.2.16.tar.gz
Algorithm Hash digest
SHA256 233627ec1c0de831b99eb38b6944ca10891d3c1c03c034d95aa497f8ae90b7d0
MD5 6ff2b0a4ed9cedb1a784d11b08dd8e9b
BLAKE2b-256 39c1eceefb3ac94cbf99030fa3eec07d32d9cbd41efdee2645a42d8e8d7172c6

See more details on using hashes here.

File details

Details for the file narration-0.2.16-py2.py3-none-any.whl.

File metadata

  • Download URL: narration-0.2.16-py2.py3-none-any.whl
  • Upload date:
  • Size: 44.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for narration-0.2.16-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2c5c62b57700c0ae55b9d7132e63f5f50a2befbc0e044196e58e620010aa04cd
MD5 d6dd4b037638ac1e36591448814c9e6b
BLAKE2b-256 715f700252388c301014a02f4693a3ef4461f2749c1d2a2be6145e41632957a9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page