How to redirect TensorFlow logging to a file?

后端 未结 4 862
无人及你
无人及你 2021-02-01 04:14

I\'m using TensorFlow-Slim, which has some useful logging printed out to console by tf.logging. I would like to redirect those loggings to a text file, but couldn\'

4条回答
  •  臣服心动
    2021-02-01 04:25

    A easy workaround would be to direct the output from command line to a file. For example,

    python training.py 1> output.log 2> error.log
    # 1 for stdout stream and 2 for stderr stream
    

    The benefit, in light of the accepted answer, is that you get ALL the logs. The reason is that not all the logging comes from python (Remember the runtime is implemented in C++). For instance, you could get very helpful debugging logging (including info about Tensor memory allocation) by setting the environment variable.

    import os
    os.environ['TF_CPP_MIN_VLOG_LEVEL'] = '3'
    

    (Do this with CAUTION. The amount of logging is staggering.)

    For a glimpse of how logging is implemented in C++,

    https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/platform/default/logging.h https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/platform/default/logging.cc

    In particular it looks like logging messages are written to stderr in this line:

    https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/platform/default/logging.cc#L73

    which I quote from the discussion here

提交回复
热议问题