astropy / astropy/ccdproc

Use of root level logging interferes with other logging when imported

Open
#811 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
93
Forks
92
Avg merge
14h 44m
Merged PRs (30d)
30

Description

In essence, if we use the python logging facility, you should be careful because when you create a logging handler for a function, it seems that it is essentially forked off the root handler. Unless you remove the root handlers they remain active. This was a problem in my case because I imported the `ImageFileCollection` function and the moment I ran it for the first time, logging was activated including the root handler. This meant when *I* tried to use logging in my program, I was getting extra copies of the logging because the root handler was also responding to my logging calls.

I removed the root handlers by issuing the following:
```
# Turn off root loggers that are activated by ImageFileCollection
for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)
```

I would suggest unless you are intending to use the root handlers in `ccdproc` that you remove them yourself when you spin up the logging. That said, if there is another suggested way to handle this situation, I would appreciate the feedback.

Contributor guide

Open the contributing guide

Research direction

Locate the ImageFileCollection entry point and inspect how it configures Python logging, especially the root handlers. Reproduce the import-and-run scenario, then verify that using ImageFileCollection does not leave root logging active or produce duplicate messages in the importing application's logs.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.