开发者

Trying to provide a global logging function

开发者 https://www.devze.com 2023-01-01 20:36 出处:网络
I typically write my scripts with a structure like s #!/usr/bin/python import stuff def do_things(): print \"FOO\"

I typically write my scripts with a structure like s

#!/usr/bin/python

import stuff

def do_things():
    print "FOO"

def main():
    do_things()

if __name__ == "__main__":
    main()

The problem I have is I'd like to have a logging function that is defined globally and I"m not really sure how to开发者_StackOverflow do this. I tried a decorator function but if I define it in main I can't call it from other functions in the script. It seems like something that should be easy to do but not something I have experience with.


import logging

Python's logging library should satisfy your requirements.

0

精彩评论

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