Where To Store A Log File Name In Python?
I have a Python program that consists of several modules. The 'main' module creates a file variable log_file for logging the output; all the other modules would need to write to th
Solution 1:
Put the "global" variable in a "settings" module.
settings.py
log_file = "/path/to/file"
main.py
import settings
import logging
logging.basicConfig(filename=settings.log_file,level=logging.DEBUG)
logging.debug("This should go to the log file")
other_module.py
import logging
logging.debug("This is a message from another place.")
While the logging module may solve your immediate problem and many others, the settings module pattern is useful for a lot of other things besides log file names. It is used by Django to configure just about everything.
Solution 2:
One way is to take all that code into another module so that you could import it in main file and other modules as well.
Hope you have checked on : http://docs.python.org/library/logging.html
Post a Comment for "Where To Store A Log File Name In Python?"