Skip to main content

A small toolkit for python multiprocessing file logging

Project description

Small Toolkit for Python Multiprocessing Logging

This is a small toolkit for solving unsafe python mutliprocess logging (file logging and rotation)

Install

Only for Python 3.5+

pip install mp-socket-logging

Features

                            (child process)
                           +---------------+
             +<------------+     client    |
 +-------+-+-+             +---------------+
 |           |              (child process)
 +  Socket   |             +---------------+
 |           +<------------+     client    |
 +---------+-+             +---------------+
       |
       |                 (main process)
       |               +---------------+          +--------------+
       +-------------->+     server    +--------->+   log file   +
                       +---------------+          +--------------+
  • The package uses unix socket for communication between processes.
  • I/O operations will all be done by server in main process.
  • Client Class itself is a logging.Handler which will be added to user's logger inside child process. Client handler will do the formatting and sending the logs to server side through socket.
  • Inside child process, user can do logging as normal with the logger.

Quick Start

  • start a server before in the main process
server_handler = ServerHandler(LOG_FILE, maxBytes=MAX_BYTES)
server_handler.setLevel(logging.INFO)
server = Server(server_handler, batch_size=BATCH_SIZE)
server.start()
  • register the client to your logger inside multiprocessing worker for sending logs to server through socket
  • you can define your own formatter to add to the handler (otherwise a default formatter will be used)
client_logger = logging.getLogger("client_logger")
formatter = logging.Formatter(
    "%(asctime)s - %(name)s - %(filename)s- [%(levelname)s]: %(message)s"
)
register_handler(client_logger, logging_level=logging.INFO, formatter=formatter)
client_logger.setLevel(logging.INFO)

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

mp-socket-logging-0.1.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

mp_socket_logging-0.1.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file mp-socket-logging-0.1.1.tar.gz.

File metadata

  • Download URL: mp-socket-logging-0.1.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for mp-socket-logging-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a2e8b742ba6afcd5e0a04eea2bbfe76d4556d3363022045bfce951ca2cd83ffb
MD5 973fc4788ccddd13cef1f74f37024c7d
BLAKE2b-256 8802024df318d7d89bb6ac4fbeb2e0c849d5cd3f78e9801dec80ce3ff2a69cc7

See more details on using hashes here.

File details

Details for the file mp_socket_logging-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mp_socket_logging-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for mp_socket_logging-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa0c8f2998e0cebcf905b97e26e15a9393c767c529ceac93e80475cae75db40f
MD5 1287bff7cb0489529ea4d71af3f974dc
BLAKE2b-256 9c2a8765d5654bee6686d421e8f0b1f68a90fd31446890b65117a338a3e922a7

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