pcl icon indicating copy to clipboard operation
pcl copied to clipboard

Added the ability to redirect logging to a callable.

Open larshg opened this issue 10 months ago • 10 comments

I'm in deep water here, but it seems to work :)

Please come with suggestions, before spent too much time in the wrong way.

Could close #5589

larshg avatar Mar 01 '25 17:03 larshg

@mvieth do you have any idea to why there is linker errors with pcl::octree:OctreeKey::maxDepth ?

larshg avatar Mar 01 '25 21:03 larshg

@mvieth do you have any idea to why there is linker errors with pcl::octree:OctreeKey::maxDepth ?

Must have something to do with the usage of maxDepth here: https://github.com/PointCloudLibrary/pcl/blob/master/octree/include/pcl/octree/impl/octree_base.hpp#L98 maxDepth is a static const member, so maybe something related to ODR-use? I have to look at your changes in detail first before I can make a more specific guess.

mvieth avatar Mar 01 '25 23:03 mvieth

Ahh, its in that print statement it fails... hmm, still odd though.

larshg avatar Mar 01 '25 23:03 larshg

Maybe pcl::console::LogRecorder should be a member of the Logger, to avoid creating a stringstream for each stream command - would that make sense?

larshg avatar Mar 02 '25 20:03 larshg

Nice for me, even if I not like too much the following:

pcl::console::Logger::getInstance().setCallback(...)

because of the getInstance() call... is there a way to remove this indirection level?

Moreover, I think that the previous callback needs to be returned from the setCallaback() call to be able to restore it.

roncapat avatar Mar 03 '25 11:03 roncapat

Nice for me, even if I not like too much the following:

pcl::console::Logger::getInstance().setCallback(...)

because of the getInstance() call... is there a way to remove this indirection level?

Moreover, I think that the previous callback needs to be returned from the setCallaback() call to be able to restore it.

Somehow the callback needs to be saved - and having just a static global variable to a std::function, didn't seem right either. At least it was the best solution I found, also browsing other logging frameworks.

larshg avatar Mar 03 '25 11:03 larshg

Moreover, why generic template "functor" instead of std::function?

roncapat avatar Mar 03 '25 12:03 roncapat

Else I couldn't get it to work with lambdas - but maybe I did it wrong 😄

larshg avatar Mar 03 '25 12:03 larshg

To restore normal logging again, you can just set the callback to a nullptr.

larshg avatar Mar 03 '25 12:03 larshg

I had a quick look and it looks promising to me, thanks for your work

aurelienrb avatar Mar 05 '25 14:03 aurelienrb