1

I was reading loggers in python and got confused with logging.basicConfig() method. As mentioned in the python docs that it set many config for root logger, does that mean that it set the configs only for root logger or does it do it even for user created loggers also ?

Another doubt is that whenever we create a user defined logger, does it become child logger of root logger ?

1 Answer 1

2

To answer your second part:

    # Pass no arguments to get the root logger
    root_logger = logging.getLogger()
    # This logger is a child of the root logger
    logger_a = logging.getLogger('foo')
    # Configure logger_a here e.g. change threshold level to logging.DEBUG
    # This is a child of logger_a
    logger_b = logging.getLogger('foo.bar')

Both logger_a and logger_b are user-defined, but only logger_a will inherit the default configuration of root_logger. If, between lines 4 & 6 of the above, you were to configure logger_a so that it had different settings to root_logger, logger_b would default to logger_a's settings rather than root_logger's, since it is a direct descendant of logger_a and not root_logger.

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

1 Comment

Thanking you for answering this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.