tags:

views:

49

answers:

1

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 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.

+3  A: 
import logging

Python's logging library should satisfy your requirements.

Johnsyweb
I did look at the logging library but for some reason I thought I had to create a logging object and pass it around to my functions as I called them instead of using it as a global object. Thanks :)
Gekitsuu
As long as you `import logging` in each module where you need it, you will be able to access your `logger` from within the `logging` namespace.
Johnsyweb
Sorry for taking so long to respond it did solve my needs perfectly!
Gekitsuu