2016-09-20 3 views
0

これはおそらく私の最後のばかげたミスですが、見つけられないようです。TensorFlowのログがコンソールに表示されず、ファイル

TensorFlowのログは、自分のコンソールとログファイルに表示したいと思います。これは、すべてのコードで動作しますが、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) 

を:

import tensorflow as tf 
... 
tf.logging.set_verbosity(tf.logging.INFO) 

残念ながら、これはいないようですログが表示されません。自分の設定ではなくlogging.basicConfig()を使用すると、ログが期待通りに表示されます。この場合、ログは端末に出力されます。

私の結論は、私のロギング設定に多少の欠陥があるということです。お手伝いをしてください。

答えて

1

Good logging practice in Pythonを読んだ後、間違いが見つかりました。 dictConfigへの呼び出しは、デフォルトでは、既存のロガーを無効にします - 私はこの(disable_existing_loggers)を解決するために設定する別のキーを追加する必要がありました:それは動作します:)

を今すぐ

# 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, 
    }, 
    disable_existing_loggers=False 
) 

関連する問題