-
Notifications
You must be signed in to change notification settings - Fork 74k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TF_RegisterLogListener in C API does not seem to work #44995
Comments
Hi @gehlhaarPfizer , when you say "log messages" do you mean all TF logging or specifically messages/tensors printed via Originally this API was created to make sure @rohan100jain to see if tf-core should revisit this. |
Ah. I misunderstood. I had expected all TensorFlow logging to go through the listener and not be output. I have a small DNN model that I built in Python and then incorporated into an existing C++ program for production deployment. I took the shortest path to put this into C++, which was through the C API. The C++ API is horribly complex. I don't understand why there isn't a C++ API as clean as the Python API. But that is a topic for another conversation. While it works correctly, I get superfluous output from TensorFlow to my console: 2020-11-23 14:06:43.917926: I tensorflow/cc/saved_model/reader.cc:31] Reading SavedModel from: /gpfs/apps/medsci/stacks/noOS/software/zing/latest/bin/../parameters/FitScoreModel.tf I would really like to redirect this to my program's internal logging mechanism, which goes to a log file. I can suppress this output entirely via an environment variable but I would prefer to redirect it. |
Seconding this on behalf of SIG JVM, we would like to be able to redirect the core logging to a Java logging API (almost certainly SLF4J). Additionally, it would be extremely nice if the callback had some structure, i.e. |
Related change: #41733 cc @avitebskiy IIRC, this is not C-API(yet) but could you try |
It seems to work to some extent, but the added sink doesn't get all messages. For example, if I just echo the data back, I see stuff like:
The Looking at the code for Building with |
System information
Describe the current behavior
When I call TF_RegisterLogListener in the C API, it doesn't seem to work as described. My listener is never called, and TensorFlow log messages still go to the console. The API description is:
// Register a listener method that processes printed messages.
//
// If any listeners are registered, the print operator will call all listeners
// with the printed messages and immediately return without writing to the
// logs.
Describe the expected behavior
My listener should be called and the messages should not be written to the console.
Standalone code to reproduce the issue
Provide a reproducible test case that is the bare minimum necessary to generate
the problem. If possible, please share a link to Colab/Jupyter/any notebook.
extern "C"
{
void logListener(const char *message)
{
// This is never called and TensorFlow log messages go to the console instead.
std::cout << "TensorFlow: " << message << std::endl;
}
}
TF_RegisterLogListener(logListener);
Other info / logs Include any logs or source code that would be helpful to
diagnose the problem. If including tracebacks, please include the full
traceback. Large logs and files should be attached.
The text was updated successfully, but these errors were encountered: