-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Added the ability to redirect logging to a callable. #6244
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
base: master
Are you sure you want to change the base?
Conversation
a544354
to
9eb28fc
Compare
@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 |
Ahh, its in that print statement it fails... hmm, still odd though. |
6d1d0a4
to
44320b0
Compare
Maybe pcl::console::LogRecorder should be a member of the Logger, to avoid creating a stringstream for each stream command - would that make sense? |
05b6bfa
to
a376418
Compare
Nice for me, even if I not like too much the following: pcl::console::Logger::getInstance().setCallback(...) because of the Moreover, I think that the previous callback needs to be returned from the |
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. |
static Logger instance; | ||
return instance; | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
template <typename Functor>
void pcl::console::Logger::setCallback(Functor&& callback){
getInstance().setCallback(std::move(callback));
}
DISCLAIMER: draft, untested code.
@larshg wouldn't this work? Would the template be a problem there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want a free function like:
template <typename Functor>
void
setCallback(Functor&& callback)
{
Logger::getInstance().setCallback(std::move(callback));
}
so you can call:
pcl::console::setCallback(...);
Yes, thats possible.
Moreover, why generic template "functor" instead of |
Else I couldn't get it to work with lambdas - but maybe I did it wrong 😄 |
To restore normal logging again, you can just set the callback to a nullptr. |
I had a quick look and it looks promising to me, thanks for your work |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume we are targeting PCL 1.16.0, due to likely ABI changes?
Is there a way to easily reset to the default behaviour, after calling setCallback
? Edit: I just read your other comment: set callback to a nullptr. Please document this in the code somewhere.
} | ||
|
||
LogRecorder& | ||
operator<<(std::ostream& (std::ostream&)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one looks strange, what is it for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was for handling std::endl if I remember correctly - that apparently need this operator.
@@ -210,7 +210,7 @@ CPCSegmentation Parameters: \n\ | |||
pcl::PCLPointCloud2 input_pointcloud2; | |||
if (pcl::io::loadPCDFile (pcd_filename, input_pointcloud2)) | |||
{ | |||
PCL_ERROR ("ERROR: Could not read input point cloud %s.\n", pcd_filename.c_str ()); | |||
PCL_ERROR ("ERROR: Could not read input point cloud %s.\n", pcd_filename); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does .c_str()
still work? But is not necessary any more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems it still is necessary. See https://godbolt.org/z/zaca3aGK3 - MSVC output correctly, but GCC output random stuff.
@@ -138,9 +138,14 @@ class OctreeKey { | |||
(!!(this->z & depthMask))); | |||
} | |||
|
|||
/* \brief maximum depth that can be addressed */ | |||
static const unsigned char maxDepth = | |||
static_cast<unsigned char>(sizeof(uindex_t) * 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to keep this and deprecate it? Same for max_sample_checks_
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess so - not sure if it will do linking errors downstream though.
common/include/pcl/console/print.h
Outdated
{ \ | ||
pcl::console::LogRecorder rec; \ | ||
rec << ARGS; \ | ||
pcl::console::LogRecord entry{pcl::console::LEVEL, rec.to_string()}; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could there be a way to tell the stringstream of LogRecorder to directly operate on the message string of the LogRecord? Otherwise there are multiple allocations and copies here, I think.
4248763
to
5384843
Compare
…t logging to console
448c188
to
746959d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot wasn't able to review any files in this pull request.
Files not reviewed (14)
- common/include/pcl/console/print.h: Language not supported
- common/src/print.cpp: Language not supported
- examples/segmentation/example_cpc_segmentation.cpp: Language not supported
- examples/segmentation/example_lccp_segmentation.cpp: Language not supported
- octree/include/pcl/octree/impl/octree2buf_base.hpp: Language not supported
- octree/include/pcl/octree/impl/octree_base.hpp: Language not supported
- octree/include/pcl/octree/impl/octree_pointcloud.hpp: Language not supported
- octree/include/pcl/octree/octree_impl.h: Language not supported
- octree/include/pcl/octree/octree_key.h: Language not supported
- octree/src/octree_inst.cpp: Language not supported
- sample_consensus/include/pcl/sample_consensus/sac_model.h: Language not supported
- test/common/CMakeLists.txt: Language not supported
- test/common/test_console.cpp: Language not supported
- tools/train_linemod_template.cpp: Language not supported
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