Skip to main content

log_safe

log_safe is a Python library that provides safe and efficient logging capabilities for multiprocessing applications. It ensures that logging is thread-safe and process-safe, making it ideal for complex, multi-process Python applications.

Features

  • Thread-safe and process-safe logging
  • Centralized log collection from multiple processes
  • Customizable logging configurations for both listener and worker processes
  • Automatic initialization of logging in child processes
  • Watchdog mechanism to prevent hanging listener process daemons
  • Seamless integration with Python's built-in multiprocessing and concurrent.futures modules

Quick Start

Here's a simple example of how to use log_safe:

from log_safe import initialize_safe_logging
import logging
import multiprocessing

initialize_safe_logging()

def worker_function():
    logger = logging.getLogger()
    logger.info("This is a log message from a worker process")

if __name__ == "__main__":
    logger = logging.getLogger()

    logger.info("Starting main process")

    with multiprocessing.Pool(processes=2) as pool:
        pool.apply_async(worker_function)
        pool.apply_async(worker_function)

    logger.info("Main process completed")

Usage

  1. Initialize logging before using any multiprocessing features:
from log_safe import initialize_safe_logging

initialize_safe_logging()
  1. Use with multiprocessing.Pool, ProcessPoolExecutor, or multiprocessing.Process as you normally would. log_safe automatically patches these to ensure proper logging initialization in all child processes.

Custom Configuration

You can provide custom configurations for both the listener and worker processes:

from log_safe import initialize_safe_logging

listener_config = {
    # ... listener configuration ...
}

worker_config = {
    # ... worker configuration ...
}

initialize_safe_logging(listener_config, worker_config)

Considerations

  • Always call initialize_safe_logging() in the main process before creating any child processes.
  • The library uses global variables to maintain the logging state. Be cautious when modifying global state in your application.
  • The watchdog mechanism will shut down the logging system if it's idle for too long (default is 10 hours). Adjust this if needed for long-running applications.

For more detailed information, use cases, and advanced usage, please refer to the full documentation on GitHub.

Metadata

Release files for log-safe 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for log-safe 0.1.2
File Size Uploaded
log_safe-0.1.2.tar.gz 9.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for log-safe 0.1.2
File Interpreter ABI Platform
log_safe-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 15.5 kB

Release files / log_safe-0.1.2.tar.gz

Download URL log_safe-0.1.2.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
cd31fd1983dab4eaa911153027a5cc95dbd0f2c4757eb60a6d8e12b3ff922433
BLAKE2b-256 checksum
How to use checksums
ac20e1945b1c5eb1166fada97664e5ae6b0392303f08784b50fb1411c70a2f3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.1

Release files / log_safe-0.1.2-py3-none-any.whl

Download URL log_safe-0.1.2-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56b2aae942cf54b926fa51bb6cd2ab0bf4dce02a1bb554e3a68634643f260b4f
BLAKE2b-256 checksum
How to use checksums
49c0326b975ca659897d4c5ecbaa596051396c40a45041a2f97f90c301320174
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.1

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page