Skip to content

Commit

Permalink
fix: log the function name, the file name, and the line number with m…
Browse files Browse the repository at this point in the history
…acros
  • Loading branch information
YuanYuYuan committed Jul 15, 2024
1 parent 5fbf902 commit 7413013
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 4 additions & 1 deletion rmw_zenoh_cpp/src/detail/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ void Logger::set_log_level(RCUTILS_LOG_SEVERITY new_level)

void Logger::log_named(
RCUTILS_LOG_SEVERITY level,
const char * function_name,
const char * file_name,
size_t line_number,
const char * name,
const char * message,
...) const
Expand All @@ -47,7 +50,7 @@ void Logger::log_named(
RCUTILS_SAFE_FWRITE_TO_STDERR("Failed to get timestamp while doing a console logging.\n");
return;
}
static rcutils_log_location_t log_location = {__func__, __FILE__, __LINE__};
static rcutils_log_location_t log_location = {function_name, file_name, line_number};
va_list args;
va_start(args, message);
rcutils_logging_console_output_handler(
Expand Down
3 changes: 3 additions & 0 deletions rmw_zenoh_cpp/src/detail/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class Logger
// Log to the console.
void log_named(
RCUTILS_LOG_SEVERITY level,
const char * function_name,
const char * file_name,
size_t line_number,
const char * name,
const char * message,
...) const;
Expand Down
10 changes: 5 additions & 5 deletions rmw_zenoh_cpp/src/detail/logging_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
// invoke GraphCache::parse_put() and GraphCache::parse_del() functions.
// See https://github.com/ros2/rmw_zenoh/issues/182 for more details.
#define RMW_ZENOH_LOG_DEBUG_NAMED(...) {rmw_zenoh_cpp::Logger::get().log_named( \
RCUTILS_LOG_SEVERITY_DEBUG, __VA_ARGS__);}
RCUTILS_LOG_SEVERITY_DEBUG, __func__, __FILE__, __LINE__, __VA_ARGS__);}
#define RMW_ZENOH_LOG_ERROR_NAMED(...) {rmw_zenoh_cpp::Logger::get().log_named( \
RCUTILS_LOG_SEVERITY_ERROR, __VA_ARGS__);}
RCUTILS_LOG_SEVERITY_ERROR, __func__, __FILE__, __LINE__, __VA_ARGS__);}
#define RMW_ZENOH_LOG_FATAL_NAMED(...) {rmw_zenoh_cpp::Logger::get().log_named( \
RCUTILS_LOG_SEVERITY_FATAL, __VA_ARGS__);}
RCUTILS_LOG_SEVERITY_FATAL, __func__, __FILE__, __LINE__, __VA_ARGS__);}
#define RMW_ZENOH_LOG_INFO_NAMED(...) {rmw_zenoh_cpp::Logger::get().log_named( \
RCUTILS_LOG_SEVERITY_INFO, __VA_ARGS__);}
RCUTILS_LOG_SEVERITY_INFO, __func__, __FILE__, __LINE__, __VA_ARGS__);}
#define RMW_ZENOH_LOG_WARN_NAMED(...) {rmw_zenoh_cpp::Logger::get().log_named( \
RCUTILS_LOG_SEVERITY_WARN, __VA_ARGS__);}
RCUTILS_LOG_SEVERITY_WARN, __func__, __FILE__, __LINE__, __VA_ARGS__);}

#endif // DETAIL__LOGGING_MACROS_HPP_

0 comments on commit 7413013

Please sign in to comment.