loguru icon indicating copy to clipboard operation
loguru copied to clipboard

Multiprocessing-Safe Logging Filter for Loguru

Open hidara2000 opened this issue 2 months ago • 1 comments

hidara2000 avatar Oct 10 '25 02:10 hidara2000

The problem description is odd:

When using enqueue=True, loguru uses multiprocessing.Queue which silently drops logs containing unpicklable objects:

Issue #399: C Extension Exceptions

# SWIG/Cython/pybind11 exceptions cannot be pickled
try:
    camera.set_feature(value)
except Exception:
    logger.exception("Camera error")  # Silently fails - no log output
**Error:** `_pickle.PicklingError: Can't pickle <class '_genapi.InvalidArgumentException'>`

Issue #498: Pydantic Models with Thread Locks

# Pydantic v1/v2 models with _thread.RLock cannot be pickled
logger.bind(user=pydantic_model).info("User action")  # Silently fails
**Error:** `_pickle.PicklingError: Can't pickle <class '_thread.RLock'>`

The log is silently dropped - no file output, no console output, no error raised.

For one thing, Loguru does not use multiprocessing.Queue, so that initial claim is plain wrong. Secondly, it asserts that logs containing unpicklable objects are silently dropped, yet it links to issues showing that such cases actually produce a _pickle.PicklingError in the program output, which clearly contradicts the claim.

Sorry, I'm not going to delve into the rest of the report given the inaccuracies of these opening assumptions.

If you have noticed that Loguru could be improved, please clarify your description of the problem with a minimal reproducible example.

Delgan avatar Oct 10 '25 07:10 Delgan