19 #include "rcl/error_handling.h"
22 #include "rclcpp/exceptions.hpp"
23 #include "rclcpp/logger.hpp"
24 #include "rclcpp/logging.hpp"
26 #include "./logging_mutex.hpp"
34 #if RCLCPP_LOGGING_ENABLED
46 if (
nullptr == logger_name) {
49 logger,
"failed to get logger name from node at address %p",
50 static_cast<void *
>(
const_cast<rcl_node_t *
>(node)));
64 std::shared_ptr<std::recursive_mutex> logging_mutex;
65 logging_mutex = get_global_logging_mutex();
67 std::lock_guard<std::recursive_mutex> guard(*logging_mutex);
72 exceptions::throw_from_rcl_error(
73 rcl_ret,
"failed to call rcl_logging_rosout_add_sublogger",
74 rcl_get_error_state(), rcl_reset_error);
78 Logger logger(*name_ + RCUTILS_LOGGING_SEPARATOR_STRING + suffix);
80 logger.logger_sublogger_pairname_.reset(
81 new std::pair<std::string, std::string>({*name_, suffix}),
82 [logging_mutex](std::pair<std::string, std::string> * logger_sublogger_pairname_ptr) {
83 std::lock_guard<std::recursive_mutex> guard(*logging_mutex);
85 logger_sublogger_pairname_ptr->first.c_str(),
86 logger_sublogger_pairname_ptr->second.c_str());
87 delete logger_sublogger_pairname_ptr;
99 rcutils_ret_t rcutils_ret = rcutils_logging_set_logger_level(
101 static_cast<RCUTILS_LOG_SEVERITY
>(level));
102 if (rcutils_ret != RCUTILS_RET_OK) {
103 if (rcutils_ret == RCUTILS_RET_INVALID_ARGUMENT) {
104 exceptions::throw_from_rcl_error(
106 rcutils_get_error_state(), rcutils_reset_error);
108 exceptions::throw_from_rcl_error(
110 rcutils_get_error_state(), rcutils_reset_error);
117 int logger_level = rcutils_logging_get_logger_effective_level(
get_name());
119 if (logger_level < 0) {
120 exceptions::throw_from_rcl_error(
122 rcutils_get_error_state(), rcutils_reset_error);
125 return static_cast<Level>(logger_level);
RCLCPP_PUBLIC void set_level(Level level)
Set level for current logger.
RCLCPP_PUBLIC Logger get_child(const std::string &suffix)
Return a logger that is a descendant of this logger.
RCLCPP_PUBLIC const char * get_name() const
Get the name of this logger.
RCLCPP_PUBLIC Level get_effective_level() const
Get effective level for current logger.
Level
An enum for the type of logger level.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_logging_rosout_add_sublogger(const char *logger_name, const char *sublogger_name)
Add a subordinate logger based on a logger.
RCL_PUBLIC RCL_WARN_UNUSED rcl_ret_t rcl_logging_rosout_remove_sublogger(const char *logger_name, const char *sublogger_name)
Remove a subordinate logger and cleans up allocated resources.
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.
RCLCPP_PUBLIC Logger get_node_logger(const rcl_node_t *node)
Return a named logger using an rcl_node_t.
RCLCPP_PUBLIC Logger get_logger(const std::string &name)
Return a named logger.
RCL_PUBLIC RCL_WARN_UNUSED const char * rcl_node_get_logger_name(const rcl_node_t *node)
Return the logger name of the node.
Structure which encapsulates a ROS Node.
#define RCL_RET_NOT_FOUND
Resource not found.
#define RCL_RET_OK
Success return code.
#define RCL_RET_INVALID_ARGUMENT
Invalid argument return code.
#define RCL_RET_ERROR
Unspecified error return code.
rmw_ret_t rcl_ret_t
The type that holds an rcl return code.