【发布时间】:2016-09-20 08:59:44
【问题描述】:
这可能只是我的一个愚蠢的错误,但我似乎找不到它。
我想在我的控制台和日志文件中查看来自 TensorFlow 的日志,它适用于我的所有代码,但 TensorFlow 部分除外。
我已经像这样配置日志记录:
from logging.config import dictConfig
...
# Setup Logging
LOGGING_CONFIG = dict(
version=1,
formatters={
# For files
'detailed': {'format':
'%(asctime)s %(name)-12s %(levelname)-8s %(message)s'},
# For the console
'console': {'format':
'[%(levelname)s] %(message)s'}
},
handlers={
'console': {
'class': 'logging.StreamHandler',
'level': logging.DEBUG,
'formatter': 'console',
},
'file': {
'class': 'logging.handlers.RotatingFileHandler',
'level': logging.DEBUG,
'formatter': 'detailed',
'filename': LOG_FILE,
'mode': 'a',
'maxBytes': 10485760, # 10 MB
'backupCount': 5
}
},
root={
'handlers': ['console', 'file'],
'level': logging.DEBUG,
},
)
dictConfig(LOGGING_CONFIG)
我研究了这个问题并了解到我必须在 TensorFlow 中启用登录功能,如下所示:
import tensorflow as tf
...
tf.logging.set_verbosity(tf.logging.INFO)
不幸的是,这似乎不起作用 - 日志没有显示。如果我使用logging.basicConfig() 而不是我自己的配置,则日志将按预期显示。在这种情况下,日志将打印到我的终端。
我的结论是,我的日志记录配置有些错误 - 请帮助我。
【问题讨论】:
标签: python python-3.x logging tensorflow