pcl icon indicating copy to clipboard operation
pcl copied to clipboard

[console] How can I redirect the log output?

Open themightyoarfish opened this issue 2 years ago • 11 comments
trafficstars

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.

themightyoarfish avatar Jan 23 '23 12:01 themightyoarfish

@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 log_file.txt:

FILE* f = fopen("log_file.txt", "w");
pcl::console::redirect_logging(pcl::console::L_WARN, f);

mvieth avatar Feb 07 '23 09:02 mvieth

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.

themightyoarfish avatar Feb 14 '23 09:02 themightyoarfish

Hello! Has such a feature been developed? It would be nice indeed to be able to intercept logs emitted by PCL, especially in GUI applications that use the library without any console attached.

aurelienrb avatar Sep 12 '23 12:09 aurelienrb