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\'
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