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']
TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks. get_logger() is used to get the logger instance. Syntax: tensorflow.get_logger() Parameters: It doesn't accept any parameters. Returns: It returns the logger instance.
import logging # get TF logger log = logging.getLogger('tensorflow') log.setLevel(logging.DEBUG) # create formatter and add it to the handlers formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') # create file handler which logs even debug messages fh = logging.FileHandler('tensorflow.log') fh.setLevel(logging.DEBUG) fh.setFormatter(formatter) log.addHandler(fh)
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With