Configure module-level logger as child of main program logger

6 days ago 3
ARTICLE AD BOX

If a python module uses the native logging module, can I configure logging in my main program such that all logging messages generated from the module goes to a custom namespace that I define in my program? For example, if I have a program like this

import httpx import logging # What to put here? if __name__ == '__main__': httpx.get("https://www.example.com") # will log something

I want all log messages generated by httpx to be output to a logger named program.network.httpx (instead of httpx, httpcore, or whatever the default is for that module) and I will later define a handler for these messages at the program level instead of program.network.

Read Entire Article