1

I am writing a python library main_lib that relies on another library dep_lib that is installed as dependency.

in both libraries each file starts with :

logger = logging.getLogger(library_name.filename)

and logs are done as:

logger.info("say somthing")

now in my main_lib I have a main method that uses function from both libraries.

I would like logs from both libraries to be printed. How should I configure the log in this main method?

2
  • Pretty confused about what you mean, could you provide a minimal working example and also provide the desired output&actual output? Or at least provide what did you get as the output for now? Commented Oct 23, 2019 at 16:02
  • sorry I have rewritten the question. I can't make minial working example as it requires to create two libraries Commented Oct 23, 2019 at 16:16

1 Answer 1

1

If there is no other code that does something to the logger than they already will print logs to stderr. If no handler is added a handler of last resort will be used, and logs with a level of error or higher will be sent to stderr.

Both handlers and loggers have a setLevel method to set which logs should be handled or ignored. In your case you can fetch the logger in main with logger = logging.getLogger(library_name.filename) and call logger.setLevel(logging.INFO) or whatever level you want on it. You can also add handlers with logger.addHandler(). Also check the documentation.

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

Comments

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.