gpt4 book ai didi

python - 如何在嵌入式 python 解释器中查看日志输出?

转载 作者:太空狗 更新时间:2023-10-30 02:19:58 25 4
gpt4 key购买 nike

我在我的 iOS 应用程序中使用嵌入式 Python 解释器。我能够在 Xcode 控制台中看到 print 输出,但我看不到任何 logging.info()logging.debug()输出。如何启用它?

我的测试 python 代码:

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

输出是:

main__()
<type 'list'>
281

最佳答案

我认为这些东西处于调试级别。这段代码对我有用:

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)

输出:

>>> main__('test')
main__()
<type 'str'>
4
t
e
s
t
>>>

关于python - 如何在嵌入式 python 解释器中查看日志输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26336365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com