Mysterious logging.basicConfig problem (Python)
I'm writing a Python script to retrieve data from Flickr. For logging 开发者_StackOverflowpurposes, I have the following setup function:
def init_log(logfile):
format = '%(asctime)s - %(levelname)s - %(message)s'
logging.basicConfig(filename=logfile,level=logging.DEBUG,format=format)
I've tested this using the python shell and it works as expected, creating a file if one doesn't already exist. But calling it from within my program is where it stops working. The function is definitely being called, and the logfile
parameter is working properly – logging.basicConfig
just isn't creating any file. I'm not even getting any errors or warnings.
My use of the Python Flickr API may be the culprit, but I doubt it. Any ideas?
The logging.basicConfig
function only does anything if the root logger has no handlers configured. If called when there are already some handlers attached to the root, it's basically a no-op (as is documented).
Possibly the Python Flickr API does some logging, in which case you may find that basicConfig should be called earlier in your code.
精彩评论