I am developping a Python app that uses TensorFlow as well as Python's standard logging
library.
Upon starting my application, I initialize logging
with my own formats and handlers. However, no matter what I do, I can't get to apply it to Tensorflow logging.
When I start a Tensorflow operation for the first time, I get lines like these output to the console (not sure if they're on stdout or stderr):
2021-11-02 14:16:05.249391: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2021-11-02 14:16:05.249576: W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303)
They don't match the format I set for my log lines and they don't get written to the log file when I use a FileHandler
.
Question: How can I get these log events to be handled by Python's logging system, or in the worst case to be removed entirely?
I am using the TensorFlow package present on PyPI and I would like to avoid re-building it at all costs.
Also I don't care about solving the warning reported by the log lines (my computer doesn't even have an Nvidia GPU), what I want is to get all TensorFlow log lines themselves either gone or handled by Python logging.
EDIT As an attempt to solve this issue, I already have following code as part of my logging intialization:
tf.autograph.set_verbosity(0)
tflogger = tf.get_logger()
tflogger.setLevel(logging.NOTSET)
for handler in tflogger.handlers[:]:
tflogger.removeHandler(handler)
tflogger.propagate = True
EDIT #2: I would like to avoid touching to environment variables in order to avoid having to set them up everytime I'm using the application (poissibly on different machines)