这是我想做的例子。如果我能够将 logging.warning() 的输出存储到变量中,我将能够将其存储到 Mongodb
import logging
logging.basicConfig(level=logging.DEBUG,filename='logDemo.log')
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
logging.basicConfig(format='%(asctime)s %(message)s')
def divide(a,b):
try :
divide = a/b
return divide
except ZeroDivisionError:
a=logging.warning('Watch out!') # will print a message to the console
logging.info('I told you so') # will not print anything
logging.warning('is when this event was logged.')
print a
divide(60,0)
我试图将 logging.warning() 的输出存储到一个变量中,但它失败了,有没有办法将日志记录函数输出存储到 mongodb