开发者

Mysterious logging.basicConfig problem (Python)

开发者 https://www.devze.com 2022-12-30 01:59 出处:网络
I\'m writing a Python script to retrieve data from Flickr. For logging 开发者_StackOverflowpurposes, I have the following setup function:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号