logger configuration to log to file and print to stdout不会和我一起工作,所以:
我既想在prog_log.txt 中打印日志记录详细信息,也想在控制台中打印,我有:
# Debug Settings
Import logging
#logging.disable() #when program ready, un-indent this line to remove all logging messages
logging.basicConfig(level=logging.DEBUG,
filename = 'prog_log.txt',
format='%(asctime)s - %(levelname)s - %(message)s',
filemode = 'w')
logging.debug('Start of Program')上面的内容确实会在prog_log.txt文件中打印日志记录详细信息,但是控制台上没有任何内容。
In [3]: runfile('/Volumes/GoogleDrive/Mon Drive/MAC_test.py', wdir='/Volumes/GoogleDrive/Mon Drive/')
...nothing...欢迎任何帮助
发布于 2021-08-02 09:34:25
logger configuration to log to file and print to stdout复本
需要添加和处理程序才能将日志设置为StreamHandler:
logging.basicConfig(level=logging.DEBUG,
filename = 'prog_log.txt',
format='%(asctime)s - %(levelname)s - %(message)s',
filemode = 'w')
logger.addHandler(logging.StreamHandler())或
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s',
filemode = 'w',
handlers=[
logging.FileHandler('prog_log.txt'),
logging.StreamHandler()
]
)https://stackoverflow.com/questions/68619227
复制相似问题