I am currently developing a package which can be used without writing any new code and the modules can be used to develop new code (see documentation).
Many of my modules use logging
in a very simple way:
import logging
import sys
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
level=logging.DEBUG,
stream=sys.stdout)
# Code of the module follows
I have these lines in many modules. It seems to me that I should factor it out, but I am not sure what the best / recommended / most pythonic way to do so is.
The relevant parts in the logging documentation seem to be Configuring Logging for a Library and Logging from multiple modules.
I guess I should simply move the line logging.basicConfig
to the executables (bin/hwrt
) and remove all other logging.basicConfig
lines.
Is there any rule how packages should use logging (like PEP8 for coding style)?
If other developers use my code they might want to disable / modify the way my package does logging (so that it doesn't get mixed with their logging calls). Is there a way to help them do so?