Joblib: Joblib hijacks the root logger

Created on 8 Jun 2018  路  9Comments  路  Source: joblib/joblib

When I clear a cache with Memory.clear:

from joblib import Memory

memory = Memory(cachedir=".")
memory.clear()

I get output on the root logger which has apparently now been configured with what looks like logging.basicConfig:

WARNING:root:[Memory(cachedir='./joblib')]: Flushing completely the cache

This goes against Python logging best practices because it's manipulating the root logger which propagates to all other loggers. An example of why this is bad practice can be seen below:

import logging
from joblib import Memory

logger = logging.getLogger("mylogger")
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())

memory = Memory(cachedir=".")
memory.clear()

logger.info("oops, I'll show up twice")

which gives the output

WARNING:root:[Memory(cachedir='./joblib')]: Flushing completely the cache
oops, I'll show up twice
INFO:mylogger:oops, I'll show up twice

What should be happening instead:

  • joblib should not use calls to logging.warning but instead create its own logger and call logger.warning instead
  • this logger should add a NullHandler so as to not interfere with existing logging
  • clearing cache should default to not give a warning in the first place since if I am calling it, I know that it's going to be cleared

Most helpful comment

Still not fixed. Does anyone have a workaround?

All 9 comments

Indeed you are correct. This happens in joblib/logger.py.

We would welcome a pull request to fix this.

Thanks!

Still not fixed. Does anyone have a workaround?

Still not fixed. Does anyone have a workaround? [2]

Same problem here. Joblib is messing up all my logging.

This is still an issue.

Any solution to this problem?

Still not fixed. Does anyone have a workaround? [3]

Hey, I just submitted a pull request for this issue. It's #1033. But for some reason a bunch of seemingly unrelated things are now failing (things like pickling io objects). The only file I changed was like 5 lines or so from Logger.py. What gives?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Piatachock picture Piatachock  路  9Comments

aseyboldt picture aseyboldt  路  3Comments

jlopezpena picture jlopezpena  路  5Comments

stroykova picture stroykova  路  4Comments

EPinzuti picture EPinzuti  路  8Comments