Skip to main content

kitty_logger

Cross-process Python logger. The main process starts a dedicated log-server subprocess; every other process (forked or spawned) ships LogRecords to it via logging.handlers.SocketHandler, so all log lines end up in one place with no interleaving or file-locking issues.

Install

pip install .

Usage

# main.py
import multiprocessing as mp
import kitty_logger

def worker(i):
    log = kitty_logger.getLogger(f"worker.{i}")
    log.info("hello from worker %d", i)

if __name__ == "__main__":
    kitty_logger.setup_logging(log_file="app.log")
    log = kitty_logger.getLogger("main")
    log.info("starting")

    with mp.get_context("spawn").Pool(4) as pool:
        pool.map(worker, range(4))

setup_logging sets the env vars KITTY_LOGGER_HOST / KITTY_LOGGER_PORT, which child processes inherit and use to connect.

API

  • setup_logging(log_file=None, level=logging.INFO, host="127.0.0.1", port=0, stream=True, console_fmt=..., file_fmt=..., datefmt=None, attach_main_logger=True) -> (host, port) Starts the log-server subprocess (always uses the spawn start method). Idempotent. Registered with atexit. port=0 lets the OS pick a free port; the actual (host, port) is returned.
  • getLogger(name=None) -> logging.Logger Returns a logger with a SocketHandler pointing at the server.
  • shutdown_logging() — stop the server subprocess explicitly.

Why spawn-only

Child processes started with fork inherit the parent's already-connected SocketHandler (and its TCP fd). Parent and child would then interleave pickled-record bytes on the same connection, which corrupts every record on the wire. fork is also unsafe in multi-threaded parents and unavailable on Windows. KittyLogger therefore only supports spawn. Use multiprocessing.get_context("spawn") (or just rely on Python's defaults under if __name__ == "__main__":).

Security

The server uses pickle to deserialize incoming LogRecords. Only ever bind to a loopback address (the default 127.0.0.1). Binding to 0.0.0.0 or any externally reachable interface exposes a remote-code-execution surface to anyone who can reach the port.

Caveats

  • Do not call logging.basicConfig() (or otherwise attach a StreamHandler to the root logger) before setup_logging(attach_main_logger=True) — the main process would emit each record twice: once via the local root handler and once via the log-server. Either let kitty_logger be the only configurer, or pass attach_main_logger=False and manage main-process handlers yourself.
  • After shutdown_logging(), kitty_logger removes its own SocketHandlers from this process's loggers and clears KITTY_LOGGER_* env vars, so the process state is symmetric with setup_logging. If you attach extra handlers yourself, you remain responsible for cleaning them up.

Metadata

Release files for kitty-logger 0.1.0

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

Source distribution (sdist)

Source distribution for kitty-logger 0.1.0
File Size Uploaded
kitty_logger-0.1.0.tar.gz 16.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kitty-logger 0.1.0
File Interpreter ABI Platform
kitty_logger-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.6 kB

Release files / kitty_logger-0.1.0.tar.gz

Download URL kitty_logger-0.1.0.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
be0d8171cf9cb9399fa6ede41433776026a95dfdc2315679a5488eb95068173e
BLAKE2b-256 checksum
How to use checksums
cd1661ae47c1833b6ca2e32d1d8fd38ec34588658d8e260039aaa62d29d87dbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / kitty_logger-0.1.0-py3-none-any.whl

Download URL kitty_logger-0.1.0-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
58d58b9d91445f215c7319972b4b78b9af6ef1dde9634d83368f9a5b790d313e
BLAKE2b-256 checksum
How to use checksums
ab011aa1df9f28ef99ee89398133cd6c98bfd751aa9f3611c03b4f70044a70cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5
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