0

I'm trying to establish logging in all modules I'm using. My project structure is

# driver.py
import logging
logger = logging.getLogger(__name__)

class driver:
    ....
# driver_wrapper.py
from driver import driver

device = driver(...)

def driver_func():
    logging.info("...")
    ....
# main.py
import logging
import driver_wrapper
logging.basicConfig(stream=sys.stdout, level=logging.WARNING)

driver_wrapper.driver_func()

My problem now is that I still get INFO level messages and also the output is 'INFO:root'. But I would expect the module name instead of root.

Is there a way to set the logging level in the main.py for all modules or is it already correct how I do it? There are a lot of posts about this problem but the solutions don't seem to work for me.

1 Answer 1

1

All your modules that use logging should have the logger = logging.getLogger(__name__) line, and thereafter you always log to e.g.logger.info(...), and never call e.g. logging.info(...). The latter is equivalent to logging to the root logger, not the module's logger. That "all your modules" includes driver_wrapper.py in your example.

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.