Skip to content
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

[Fix] switch to ROS_LOGGER from CONSOLE_BRIDGE #874

Merged
merged 6 commits into from
May 1, 2018

Conversation

jeasinema
Copy link
Contributor

@jeasinema jeasinema commented Apr 30, 2018

Description

This pull request is an extended version of #859 and inspired by #860. As suggested by @davetcoleman and @v4hn, I switched to use ROS_LOGGER from CONSOLE_BRIDGE and removed the dependency from some cmake files.

Checklist

  • Required: Code is auto formatted using clang-format
  • Extended the tutorials / documentation, if necessary reference
  • Include a screenshot if changing a GUI
  • Optional: Created tests, which fail without this PR reference
  • Optional: Decide if this should be cherry-picked to other current ROS branches (Indigo, Jade, Kinetic)

@@ -73,13 +73,14 @@ void moveit::tools::BackgroundProcessing::processingThread()
action_lock_.unlock();
try
{
CONSOLE_BRIDGE_logDebug("moveit.background: Begin executing '%s'", action_name.c_str());
ROS_DEBUG_NAMED("background_processing", "moveit.background: Begin executing '%s'", action_name.c_str());
Copy link
Contributor

@rhaschke rhaschke Apr 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the namespace introduced. However, then you can remove moveit.background: from the message.

@@ -13,16 +13,16 @@ add_library(${MOVEIT_LIB_NAME}
)
set_target_properties(${MOVEIT_LIB_NAME} PROPERTIES VERSION ${${PROJECT_NAME}_VERSION})

target_link_libraries(${MOVEIT_LIB_NAME} moveit_robot_state ${catkin_LIBRARIES} ${console_bridge_LIBRARIES} ${urdfdom_LIBRARIES} ${urdfdom_headers_LIBRARIES} ${Boost_LIBRARIES})
target_link_libraries(${MOVEIT_LIB_NAME} moveit_robot_state ${catkin_LIBRARIES} ${urdfdom_LIBRARIES} ${urdfdom_headers_LIBRARIES} ${Boost_LIBRARIES})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remember to add ${ros_console_LIBRARIES} instead everywhere.

Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your effort. I have a few comments to the naming of the loggers.
In general I like the idea of using a static const variable, e.g. logger_name, to define the logger name only once per cpp file.

@@ -12,8 +12,6 @@ endif()

find_package(Boost REQUIRED system filesystem date_time thread iostreams)

find_package(console_bridge REQUIRED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of console_bride, you need to require ros_console now...

}
else if (type == AllowedCollision::CONDITIONAL)
{
cdata->acm_->getAllowedCollision(cd1->getID(), cd2->getID(), dcf);
if (cdata->req_->verbose)
CONSOLE_BRIDGE_logDebug("Collision between '%s' and '%s' is conditionally allowed", cd1->getID().c_str(),
cd2->getID().c_str());
ROS_DEBUG_NAMED("collision_detection_fcl", "Collision between '%s' and '%s' is conditionally allowed",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to use the hierarchical logger scope collision_detection.fcl here.

@@ -139,13 +139,13 @@ int main(int argc, char* argv[])
num_failed_calls++;
++i;
if (i % 100 == 0)
ROS_INFO_NAMED("measure_ik_call_cost",
ROS_INFO_NAMED("cached_ik_kinematics_plugin",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you changed the logger name here? In order to include cached_ik, I would suggest cached_ik.measure_ik_call_cost. Remember that the package name (moveit_kinematics) is always part of the logger name.

@@ -161,7 +161,7 @@ class IKFastKinematicsPlugin : public kinematics::KinematicsBase
const size_t num_joints_;
std::vector<int> free_params_;
bool active_; // Internal variable that indicates whether solvers are configured and ready
const std::string name_{ "ikfast" };
const std::string name_{ "ikfast_kinematics_plugin" };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to keep the short name ikfast. moveit_kinematics is part of the logger name anyway.

@@ -52,19 +52,19 @@ ChainIkSolverPos_NR_JL_Mimic::ChainIkSolverPos_NR_JL_Mimic(const Chain& _chain,
{
mimic_joints[i].reset(i);
}
ROS_DEBUG_NAMED("kdl", "Limits");
ROS_DEBUG_NAMED("kdl_kinematics_plugin", "Limits");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for ikfast.

@@ -63,7 +63,7 @@ bool SrvKinematicsPlugin::initialize(const std::string& robot_description, const
{
bool debug = false;

ROS_INFO_STREAM_NAMED("srv", "SrvKinematicsPlugin initializing");
ROS_INFO_STREAM_NAMED("srv_kinematics_plugin", "SrvKinematicsPlugin initializing");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same again. Keep short name.

@@ -481,8 +481,8 @@ class MoveGroupInterface::MoveGroupInterfaceImpl
}
else
{
logError("Unable to transform from frame '%s' to frame '%s'", frame.c_str(),
getRobotModel()->getModelFrame().c_str());
ROS_ERROR_NAMED("Unable to transform from frame '%s' to frame '%s'", frame.c_str(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the logger name is missing!

@@ -52,7 +52,7 @@ class MoveItSimpleControllerManager : public moveit_controller_manager::MoveItCo
{
if (!node_handle_.hasParam("controller_list"))
{
ROS_ERROR_STREAM_NAMED("manager", "No controller_list specified.");
ROS_ERROR_STREAM_NAMED("moveit_simple_controller_manager", "No controller_list specified.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we don't need an additional name at all. moveit_simple_controller_manager is already the package name.

Copy link
Member

@davetcoleman davetcoleman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a quick run-through and I'm excited about this PR! I can re-review after @rhaschke's comments are addressed

@v4hn v4hn mentioned this pull request May 1, 2018
@jeasinema
Copy link
Contributor Author

Thanks @rhaschke @davetcoleman for the reviews. I've made some fixes on my patch following your suggestions.

@v4hn
Copy link
Contributor

v4hn commented May 1, 2018

I encouraged @jeasinema to work on this patch and supervised it in person.
He addresses my last verbal feedback right now. After this is pushed, I approve this request.

Still, @davetcoleman, please look over it once more before you merge because it's just too big to verify everything in detail.

This should be merged soon, because it probably conflicts with many other patches.

Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeasinema Thanks a lot for your effort so far. May I ask for the following changes

  • Use file-local variables static const char* LOGGER to specify the logger name once per cpp file.
  • I have suggested different logger names at various locations (see inline comments).
  • Manually fix badly clang-formatted string literals.

"Collision checking is considered complete due to external callback. %s was found. %u contacts are "
"stored.",
cdata->res_->collision ? "Collision" : "No collision", (unsigned int)cdata->res_->contact_count);
ROS_INFO_NAMED("collision_detection.fcl", "Collision checking is considered complete due to external callback. "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you fix such weird line breaks in string literals. clang-format doesn't remove line breaks in string literals, but only adds new ones...
When I did that manually the last time, I tried to keep sentences (or phrases) on a single line.

@@ -106,7 +106,7 @@ int PR2ArmIKSolver::CartToJnt(const KDL::JntArray& q_init, const KDL::Frame& p_i
if (free_angle_ == 0)
{
if (verbose)
ROS_DEBUG_NAMED("pr2_arm_kinematics_plugin", "Solving with %f", q_init(0));
ROS_DEBUG_NAMED("constraint_samplers", "pr2_arm_kinematics_plugin", "Solving with %f", q_init(0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot use two logger names. This applies to all the following logging calls.
Why doesn't this raise a warning?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would raise an error with ROS_DEBUG_STREAM_NAMED, but printf-style formatting is syntactically fine with three strings in the parameter list...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, this should finally end up in an printf-like command and gcc provides some extra checks for these...


moveit::ConstructException::ConstructException(const std::string& what_arg) : std::runtime_error(what_arg)
{
CONSOLE_BRIDGE_logError("Error during construction of object: %s\nException thrown.", what_arg.c_str());
ROS_ERROR_NAMED("exceptions", "Error during construction of object: %s\nException thrown.", what_arg.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I suggest to drop the extra logger name and use ROS_ERROR() only. Applies to next as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree.
It is not unlikely that we might want to silence errors from these classes only.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Agreed.

@@ -295,7 +294,7 @@ const LinkModel* JointModelGroup::getLinkModel(const std::string& name) const
LinkModelMapConst::const_iterator it = link_model_map_.find(name);
if (it == link_model_map_.end())
{
CONSOLE_BRIDGE_logError("Link '%s' not found in group '%s'", name.c_str(), name_.c_str());
ROS_ERROR_NAMED("robot_model", "Link '%s' not found in group '%s'", name.c_str(), name_.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I suggest to use robot_model.jmg as the logger name (in whole file).

@@ -93,7 +92,8 @@ bool IterativeSplineParameterization::computeTimeStamps(robot_trajectory::RobotT
const robot_model::JointModelGroup* group = trajectory.getGroup();
if (!group)
{
CONSOLE_BRIDGE_logError("It looks like the planner did not set the group the plan was computed for");
ROS_ERROR_NAMED("trajectory_processing", "It looks like the planner did not set the group the plan was computed "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger name: trajectory_processing.iterative_spline_parameterization?

@@ -270,11 +270,12 @@ void ompl_interface::ConstraintsLibrary::loadConstraintApproximations(const std:
std::ifstream fin((path + "/manifest").c_str());
if (!fin.good())
{
logWarn("Manifest not found in folder '%s'. Not loading constraint approximations.", path.c_str());
ROS_WARN_NAMED("constraints_library", "Manifest not found in folder '%s'. Not loading constraint approximations.",
Copy link
Contributor

@rhaschke rhaschke May 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be ompl.constraints_library.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package name already is ompl_interface. Adding ompl.xyz would be redundant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.

@@ -54,7 +54,7 @@ ompl_interface::ConstrainedGoalSampler::ConstrainedGoalSampler(
{
if (!constraint_sampler_)
default_sampler_ = si_->allocStateSampler();
logDebug("Constructed a ConstrainedGoalSampler instance at address %p", this);
ROS_DEBUG_NAMED("constrained_goal_sampler", "Constructed a ConstrainedGoalSampler instance at address %p", this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, logger name should be prefixed with ompl: ompl.constrained_goal_sampler.

@@ -116,7 +116,7 @@ bool ompl_interface::StateValidityChecker::isValidWithoutCache(const ompl::base:
if (!si_->satisfiesBounds(state))
{
if (verbose)
logInform("State outside bounds");
ROS_INFO_NAMED("state_validity_checker", "State outside bounds");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ompl.state_validity_checker

@@ -89,7 +89,7 @@ void ompl_interface::ModelBasedPlanningContext::setProjectionEvaluator(const std
{
if (!spec_.state_space_)
{
logError("No state space is configured yet");
ROS_ERROR_NAMED("model_based_planning_context", "No state space is configured yet");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only ompl?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the ompl package is too big and confusing to use the top-level namespace here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And as you stated above, the package name is something like ompl already...

@@ -69,7 +69,8 @@ class MoveItSimpleControllerManager : public moveit_controller_manager::MoveItCo
{
if (!controller_list[i].hasMember("name") || !controller_list[i].hasMember("joints"))
{
ROS_ERROR_STREAM_NAMED("manager", "Name and joints must be specifed for each controller");
ROS_ERROR_STREAM_NAMED("manager", "Name and joints must be specifed for each "
"controller");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typical example of bad clang-formatting that should be fixed manually.

@v4hn
Copy link
Contributor

v4hn commented May 1, 2018

Use file-local variables static const char* LOGGER to specify the logger name once per cpp file.

I know this redundancy annoys you to no end, but I would like to keep this as is.

  • search&replace is simple enough if we ever need to change
  • nobody says that we need to have only one ns per file (I'm not sure whether this is the case atm)
  • it requires yet another convention in the code base that new contributors will fail to adhere to
  • It should be obvious from the local context of the log what exactly will be logged where.

@rhaschke
Copy link
Contributor

rhaschke commented May 1, 2018

I know this redundancy annoys you to no end, but I would like to keep this as is.

Yes, it does.

search&replace is simple enough if we ever need to change
nobody says that we need to have only one ns per file (I'm not sure whether this is the case atm)

But you could have different LOGGER variables then.

It requires yet another convention in the code base that new contributors will fail to adhere to

Valid point. But failures can be fixed later too...

It should be obvious from the local context of the log what exactly will be logged where.

That's the one convincing me to some extend. However not sure, this balances out the redundancy drawback. Using modern IDEs, it's rather easy to click on the variable and see its definition.
@davetcoleman also introduced variable for logger names: 2d943ea.

@v4hn
Copy link
Contributor

v4hn commented May 1, 2018

But failures can be fixed later too...

As long as you're the one who does that (for the next 10+ years).
We have way too much code that needs fixes already.

Using modern IDEs, it's rather easy to click on the variable and see its definition.

I know a number of people who browse MoveIt source code on GitHub instead of cloning the repository and starting up their ema... eclipse. I still don't like your IDE-arguments, but we discussed this before.

@davetcoleman also introduced variable for logger names: 2d943ea.

And I'm not convinced the way he did it is very good...

Lastly, I believe @jeasinema did a very good job already and I would not make this request depend on him going over all the changes yet another time.

If you think this really blocks the request, then we should wait for a third opinion.

@rhaschke
Copy link
Contributor

rhaschke commented May 1, 2018

I agree that @jeasinema did a great job on this. However, if we already touch most of the logging stuff anyway, we should try to commit the final solution and not start touching everything yet another time.
I agree to accept as is if you insist, but I definitely prefer to have another opinion. If this doesn't arrive soon however, I suggest to merge to avoid conflicts with further PRs.

@v4hn v4hn merged commit 6bf3d04 into moveit:kinetic-devel May 1, 2018
@davetcoleman
Copy link
Member

Use file-local variables static const char* LOGGER to specify the logger name once per cpp file.

While I agree this wasn't needed in this PR (already large enough, need to move fast) I certainly agree with @rhaschke this is a cleaner approach to do in the future. I've been using that standard in my personal projects for years and I've added it in several places in the MoveIt! codebase already (Robert pointed out one)

@jeasinema thanks so much for this contribution!

@rhaschke
Copy link
Contributor

rhaschke commented May 1, 2018

@jeasinema @v4hn Your changes introduced 10 new warnings on the ROS build farm:
Please fix them asap. They are all related to wrong usage of logging arguments - see #874 (comment).

@rhaschke
Copy link
Contributor

rhaschke commented May 1, 2018

@davetcoleman @v4hn Should we consider compiler warnings as errors on Travis to avoid such issues in future?

@davetcoleman
Copy link
Member

yes I am a strong fan of making our built more strict with warnings and (long term) clang-tidy checks

@v4hn
Copy link
Contributor

v4hn commented May 2, 2018 via email

dg-shadow pushed a commit to shadow-robot/moveit that referenced this pull request Jul 30, 2018
* [Fix] switch to ROS_LOGGER from CONSOLE_BRIDGE

* [Fix] clang format

* [Fix] manually fix bad clang-formatting in strings
sjahr pushed a commit to sjahr/moveit that referenced this pull request Jun 21, 2024
* Limiting the scope of variables moveit#874

Limited the scope of variables in moveit_core/collision_detection

* Update moveit_core/collision_detection/src/collision_octomap_filter.cpp

Co-authored-by: AndyZe <andyz@utexas.edu>

* Update moveit_core/collision_detection/src/collision_octomap_filter.cpp

Co-authored-by: AndyZe <andyz@utexas.edu>

* Update moveit_core/collision_detection/src/collision_octomap_filter.cpp

Co-authored-by: AndyZe <andyz@utexas.edu>

* convert float to double

* change double to float

* Feedback fixes

* Introduced variables removed from previous merge commit

* Updated GL_Renderer function definitions with double instead of float

* Changed update() function arguments to float since it is a derived virtual function and needs to be overriden

* Fixed all override errors in visualization

* *Fixed override errors in perception
*Changed reinterpret_cast to double* from float*

* change variable types to fit function definition

* Fixed clang-tidy warnings

* Fixed scope of reusable variables

---------

Co-authored-by: Salah Soliman <salahsoliman96@gmail.com>
Co-authored-by: AndyZe <andyz@utexas.edu>
Co-authored-by: Henning Kayser <henningkayser@picknik.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants