-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
[console] How can I redirect the log output? #5589
Comments
@themightyoarfish I would want to avoid depending on a logging library if possible. Adding new dependencies is always a big pain (need to check the license, need to make sure the dependency is available on all systems and in all package managers, have to be sure that the dependency will be maintained in the future, if there are bugs in the dependency we often have to deal with them (as we experienced several times with VTK)). What do you think about the following function: void redirect_logging (VERBOSITY_LEVEL level, FILE *stream); Then you could for example redirect all WARNINGS to FILE* f = fopen("log_file.txt", "w");
pcl::console::redirect_logging(pcl::console::L_WARN, f); |
Something like that would be helpful, yes. No full logging library needed, just a way to intercept PCL logs to redirect them into our own logging. |
Hello! |
I'm also interested in this, to forward all logs to ROS 2 logger. |
@roncapat I am not so familiar with the ROS 2 logging, do you have a suggestion how to achieve forwarding? What does PCL have to offer to make that possible? Would my earlier idea ( |
The most flexible solution would just be to be able to register a log callback (or callable, better yet), then the user can do with the info whatever they wish. |
Hello!
It's more flexible than to redirect to a file:
|
Yes I agree that a generic callback with a sound signature, passing like at least the PCL log level and a message string would be nice, allowing flexibility. Draft example: auto cb = [](VERBOSITY_LEVEL level, const std::string & message) -> void {
// do something with the string, maybe considering (or not) the delcared PCL log level.
};
pcl::console::redirect_logging(&cb); |
And have the ability to pass in some user data, either via a void* pointer argument, or by being able to register any callable. Otherwise the user will be forced to use global logging, without ability to separate logs based on which object/module spawned them. |
Yes. You may consider extra 2 points:
And as suggested by @themightyoarfish accepting a struct LogRecord
{
VERBOSITY_LEVEL level;
std::string_view message;
};
auto cb = [mylogger](const LogRecord & r) {
mylogger->log(r.level, r.message);
};
pcl::console::redirect_logging(&cb); |
For your information: pull request #6244 Comments and suggestions welcome |
I think the answer currently is "you can't", as macros in
common/include/pcl/console/print.h
always log to stdout. It would be extremely useful to globally redirect logging, or rather configure log handlers so any issues can be written to the application log file to troubleshoot.Context
I get warnings only on stdout and thus cannot associate them with other stuff happening in my running application.
Expected behavior
A functionality to handle log messages in application code.
Current Behavior
Log always pollutes
cout
.Describe the solution you'd like
E.g. a logging library providing this functionality is used.
Describe alternatives you've considered
Can't see any.
The text was updated successfully, but these errors were encountered: