20 #include "rcl_logging_interface/rcl_logging_interface.h"
21 #include "rcl/error_handling.h"
24 #include "rclcpp/exceptions.hpp"
25 #include "rclcpp/logger.hpp"
26 #include "rclcpp/logging.hpp"
28 #include "./logging_mutex.hpp"
36 #if RCLCPP_LOGGING_ENABLED
48 if (
nullptr == logger_name) {
51 logger,
"failed to get logger name from node at address %p",
52 static_cast<void *
>(
const_cast<rcl_node_t *
>(node)));
61 char * log_dir = NULL;
62 auto allocator = rcutils_get_default_allocator();
63 rcl_logging_ret_t ret = rcl_logging_get_logging_directory(allocator, &log_dir);
64 if (RCL_LOGGING_RET_OK != ret) {
65 rclcpp::exceptions::throw_from_rcl_error(ret);
67 std::string path{log_dir};
68 allocator.deallocate(log_dir, allocator.state);
80 std::shared_ptr<std::recursive_mutex> logging_mutex;
81 logging_mutex = get_global_logging_mutex();
83 std::lock_guard<std::recursive_mutex> guard(*logging_mutex);
88 exceptions::throw_from_rcl_error(
89 rcl_ret,
"failed to call rcl_logging_rosout_add_sublogger",
90 rcl_get_error_state(), rcl_reset_error);
94 Logger logger(*name_ + RCUTILS_LOGGING_SEPARATOR_STRING + suffix);
96 logger.logger_sublogger_pairname_.reset(
97 new std::pair<std::string, std::string>({*name_, suffix}),
98 [logging_mutex](std::pair<std::string, std::string> * logger_sublogger_pairname_ptr) {
99 std::lock_guard<std::recursive_mutex> guard(*logging_mutex);
101 logger_sublogger_pairname_ptr->first.c_str(),
102 logger_sublogger_pairname_ptr->second.c_str());
103 delete logger_sublogger_pairname_ptr;
115 rcutils_ret_t rcutils_ret = rcutils_logging_set_logger_level(
117 static_cast<RCUTILS_LOG_SEVERITY
>(level));
118 if (rcutils_ret != RCUTILS_RET_OK) {
119 if (rcutils_ret == RCUTILS_RET_INVALID_ARGUMENT) {
120 exceptions::throw_from_rcl_error(
122 rcutils_get_error_state(), rcutils_reset_error);
124 exceptions::throw_from_rcl_error(
126 rcutils_get_error_state(), rcutils_reset_error);
133 int logger_level = rcutils_logging_get_logger_effective_level(
get_name());
135 if (logger_level < 0) {
136 exceptions::throw_from_rcl_error(
138 rcutils_get_error_state(), rcutils_reset_error);
141 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 std::filesystem::path get_log_directory()
Get the current logging directory.
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.