2

I am writing a package that has a __main__.py with something like:

def main(): logging.basicConfig(level=logging.INFO) print(logging.getLogger(__name__)) if __name__ == "__main__": main() 

And I am running it like so:

python3 -m my_package 

And seeing:

<Logger __main__ (ERROR)> 

instead of INFO. And so none of my log messages are showing up on the screen.

Why is basicConfig not having effect?

4
  • This works fine for me. What code are you using to log a message? Commented Mar 26, 2023 at 1:34
  • The usual. logging.info(“something”). Tried setting level to debug and logging.debug didn’t show up either. The level remains set to ERROR for some reason. Commented Mar 26, 2023 at 1:59
  • Ok, I have narrowed the reason down to a third-party package that I am using. It might be doing something bad that is causing my basicConfig to not work. What's a good way to ignore what that package might be doing with logging and enforce my own rules? Commented Mar 26, 2023 at 2:09
  • I think I see my answer here - stackoverflow.com/questions/38537905/set-logging-levels basicConfig doesn't work if something else is setting root handler. I should use getLogger to get the logger and set its level. Trying now. Commented Mar 26, 2023 at 2:13

1 Answer 1

3

Another package I was importing was setting logging upfront, and my basicConfig settings were not overriding. I added force=True to my basicConfig call and it works now.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.