n8henrie / jupyter-black

A simple extension for Jupyter Notebook and Jupyter Lab to beautify Python code automatically using Black. Fork of dnanhkhoa/nb_black.
MIT License
55 stars 3 forks source link

Root logger potentially conflicting with users' loggers #9

Open lurco opened 1 week ago

lurco commented 1 week ago

My Issue

The logger in the project sets the basic configuration for the root logger and if a user intends to use his own logger there might be issues (related to the way the config inheritence works in the logging module):

I propose to add a simple flag to the load function that disables the logger for the convenience of the user:

def load(
...
disable_logger: bool = False,
...) -> None:
    if disable_logger:
        rootLogger = logging.getLogger()
        for handler in rootLogger.handlers:
            rootLogger.removeHandler(handler)

WHYT

As a user trying to use my logger with a custom handler I tried:

The one thing that I found that works is the snippet i presented above and I think it would reasonable to take the onus of disarming the root logger off the user and enable this in the jupyter_black setup itself since the logs from the formatter are something a user interested in detailed logging might want to have an easier control over.


Please make sure you've taken these steps before submitting a new issue:

n8henrie commented 6 days ago

Thanks for the issue! Short on time this week due to a big exam next week, will look into this further soon.

lurco commented 5 days ago

Thanks for the reply, good louch on your exam then!