Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see logging output in embedded python interpreter?

I'm using embedded python interpreter in my iOS app. I'm able to see print output in Xcode console, but i'm unable to see any logging.info() or logging.debug() output. How can i enable it?

My test python code:

import logging
import sys

# try to add logging output to stdout
logging.basicConfig()
log = logging.getLogger()

log.addHandler(logging.StreamHandler())
log.addHandler(logging.StreamHandler(sys.stdout))

# for calling from outside
def main__(args):
    print("main__()") # can see output
    print type(args)
    print len(args)
    for eachArg in args:
#        print('#: %s' % eachArg) # can see output
        logging.info(eachArg) # can NOT see output

Output is:

main__()
<type 'list'>
281
like image 566
4ntoine Avatar asked Oct 13 '14 09:10

4ntoine


1 Answers

I think the stuff is in debug level. This code works for me:

import logging
import sys

log = logging.getLogger()
log.setLevel(logging.DEBUG)
stream = logging.StreamHandler(sys.stdout)
stream.setLevel(logging.DEBUG)
log.addHandler(stream)

# for calling from outside
def main__(args):
    print("main__()") # can see output
    print type(args)
    print len(args)
    for eachArg in args:
        logging.info(eachArg)

output:

>>> main__('test')
main__()
<type 'str'>
4
t
e
s
t
>>> 
like image 64
coldmind Avatar answered Oct 24 '22 06:10

coldmind