Skip to content

Commit e42fd71

Browse files
refactor(motion_utils): supress log message with rclcpp logging (#6955)
* refactor(motion_utils): supress log message with rclcpp logging Signed-off-by: Muhammad Zulfaqar Azmi <zulfaqar.azmi@tier4.jp> * remove std string Signed-off-by: Muhammad Zulfaqar Azmi <zulfaqar.azmi@tier4.jp> --------- Signed-off-by: Muhammad Zulfaqar Azmi <zulfaqar.azmi@tier4.jp>
1 parent 3d849e9 commit e42fd71

File tree

4 files changed

+88
-72
lines changed

4 files changed

+88
-72
lines changed

common/motion_utils/include/motion_utils/resample/resample_utils.hpp

+15-11
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ namespace resample_utils
2727
{
2828
constexpr double close_s_threshold = 1e-6;
2929

30-
#define log_error(message) std::cerr << "\033[31m " << message << " \033[0m" << std::endl;
30+
static inline rclcpp::Logger get_logger()
31+
{
32+
constexpr const char * logger{"motion_utils.resample_utils"};
33+
return rclcpp::get_logger(logger);
34+
}
3135

3236
template <class T>
3337
bool validate_size(const T & points)
@@ -62,27 +66,27 @@ bool validate_arguments(const T & input_points, const std::vector<double> & resa
6266
{
6367
// Check size of the arguments
6468
if (!validate_size(input_points)) {
65-
log_error("[resample_utils] invalid argument: The number of input points is less than 2");
69+
RCLCPP_DEBUG(get_logger(), "invalid argument: The number of input points is less than 2");
6670
tier4_autoware_utils::print_backtrace();
6771
return false;
6872
}
6973
if (!validate_size(resampling_intervals)) {
70-
log_error(
71-
"[resample_utils] invalid argument: The number of resampling intervals is less than 2");
74+
RCLCPP_DEBUG(
75+
get_logger(), "invalid argument: The number of resampling intervals is less than 2");
7276
tier4_autoware_utils::print_backtrace();
7377
return false;
7478
}
7579

7680
// Check resampling range
7781
if (!validate_resampling_range(input_points, resampling_intervals)) {
78-
log_error("[resample_utils] invalid argument: resampling interval is longer than input points");
82+
RCLCPP_DEBUG(get_logger(), "invalid argument: resampling interval is longer than input points");
7983
tier4_autoware_utils::print_backtrace();
8084
return false;
8185
}
8286

8387
// Check duplication
8488
if (!validate_points_duplication(input_points)) {
85-
log_error("[resample_utils] invalid argument: input points has some duplicated points");
89+
RCLCPP_DEBUG(get_logger(), "invalid argument: input points has some duplicated points");
8690
tier4_autoware_utils::print_backtrace();
8791
return false;
8892
}
@@ -95,23 +99,23 @@ bool validate_arguments(const T & input_points, const double resampling_interval
9599
{
96100
// Check size of the arguments
97101
if (!validate_size(input_points)) {
98-
log_error("[resample_utils] invalid argument: The number of input points is less than 2");
102+
RCLCPP_DEBUG(get_logger(), "invalid argument: The number of input points is less than 2");
99103
tier4_autoware_utils::print_backtrace();
100104
return false;
101105
}
102106

103107
// check resampling interval
104108
if (resampling_interval < motion_utils::overlap_threshold) {
105-
log_error(
106-
"[resample_utils] invalid argument: resampling interval is less than " +
107-
std::to_string(motion_utils::overlap_threshold));
109+
RCLCPP_DEBUG(
110+
get_logger(), "invalid argument: resampling interval is less than %f",
111+
motion_utils::overlap_threshold);
108112
tier4_autoware_utils::print_backtrace();
109113
return false;
110114
}
111115

112116
// Check duplication
113117
if (!validate_points_duplication(input_points)) {
114-
log_error("[resample_utils] invalid argument: input points has some duplicated points");
118+
RCLCPP_DEBUG(get_logger(), "invalid argument: input points has some duplicated points");
115119
tier4_autoware_utils::print_backtrace();
116120
return false;
117121
}

0 commit comments

Comments
 (0)