For previous versions of TensorFlow, we've been overriding handlers of tf.logging._logger
to get custom logging behavior used in the rest of our python codebase:
For example, on TF 1.7, the following snippet (some logging boilerplate omitted)
import tensorflow as tf
tf.logging.set_verbosity(tf.logging.INFO)
tf_logging = tf.logging._logger
tf_logging.handlers = [_std_out_handler()]
tf_logging.propagate = False
_logging.info("EXPECTED LOG FORMAT")
tf.logging.info("TF LOG FORMAT")
produces
[INFO |mrtx] 2018-05-18 15:10:07,613 /merantix_core/common/util/logging.py:189 --- EXPECTED LOG FORMAT
[INFO |mrtx] 2018-05-18 15:10:07,614 /usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/tf_logging.py:116 --- TF LOG FORMAT
In TF 1.8, tf.logging._logger
is no longer accessible. Based on this thread, I tried setting
tf_logging = _logging.getLogger('tensorflow')
in the above snippet, but the output is
[INFO |mrtx] 2018-05-18 15:20:34,043 /merantix_core/common/util/logging.py:190 --- EXPECTED LOG FORMAT
INFO:tensorflow:TF LOG FORMAT
I don't see any changes to tf_logging.py between TF 1.7 and 1.8 . I assume the tf_export calls weren't being enforced before, but are being enforced now. Is there still some way to override handlers for tf.logging
? Alternatively, is there a more canonical way to get the above functionality?
You can still access the tensorflow logger by directly importing the logging module:
from tensorflow.python.platform import tf_logging
tf_logger = tf_logging._get_logger()
tf_logger.handlers = handlers
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