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't find a way doing so. I looked at the tf_logging.py
source code, which exposes the following, but doesn't seem to have the option to write logs to a file. Please let me know if I missed something.
__all__ = ['log', 'debug', 'error', 'fatal', 'info', 'warn', 'warning',
'DEBUG', 'ERROR', 'FATAL', 'INFO', 'WARN',
'flush', 'log_every_n', 'log_first_n', 'vlog',
'TaskLevelStatusMessage', 'get_verbosity', 'set_verbosity']
My solution is inspired by this thread.
You are right, there are no knobs for you to do that.
If you truly, positively, absolutely cannot live with that,
tf.logging
is based on python logging. So,import logging tf.logging._logger.basicConfig(filename='tensorflow.log', level=logging.DEBUG)
Note that you are on your own on an unsupported path, and that behavior may break at anytime.
You may also file a feature request at our github issue page.
If you are using python logging in your project, one of the option will be to define the logger with name "tensorflow" in a logging config file.
Then
_logger = _logging.getLogger('tensorflow')
will use the logger and specified handlers from your config file.A easy workaround would be to direct the output from command line to a file. For example,
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.
(Do this with CAUTION. The amount of logging is staggering.)
For a glimpse of how logging is implemented in C++,
which I quote from the discussion here