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)));
60 # pragma GCC diagnostic push
61 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
63 # pragma warning(push)
64 # pragma warning(disable: 4996)
69 char * log_dir = NULL;
70 auto allocator = rcutils_get_default_allocator();
71 rcl_logging_ret_t ret = rcl_logging_get_logging_directory(allocator, &log_dir);
72 if (RCL_LOGGING_RET_OK != ret) {
73 rclcpp::exceptions::throw_from_rcl_error(ret);
75 std::string path{log_dir};
76 allocator.deallocate(log_dir, allocator.state);
81 # pragma GCC diagnostic pop
89 char * log_dir = NULL;
90 auto allocator = rcutils_get_default_allocator();
91 rcl_logging_ret_t ret = rcl_logging_get_logging_directory(allocator, &log_dir);
92 if (RCL_LOGGING_RET_OK != ret) {
93 rclcpp::exceptions::throw_from_rcl_error(ret);
95 std::string path{log_dir};
96 allocator.deallocate(log_dir, allocator.state);
108 std::shared_ptr<std::recursive_mutex> logging_mutex;
109 logging_mutex = get_global_logging_mutex();
111 std::lock_guard<std::recursive_mutex> guard(*logging_mutex);
116 exceptions::throw_from_rcl_error(
117 rcl_ret,
"failed to call rcl_logging_rosout_add_sublogger",
118 rcl_get_error_state(), rcl_reset_error);
122 Logger logger(*name_ + RCUTILS_LOGGING_SEPARATOR_STRING + suffix);
124 logger.logger_sublogger_pairname_.reset(
125 new std::pair<std::string, std::string>({*name_, suffix}),
126 [logging_mutex](std::pair<std::string, std::string> * logger_sublogger_pairname_ptr) {
127 std::lock_guard<std::recursive_mutex> guard(*logging_mutex);
129 logger_sublogger_pairname_ptr->first.c_str(),
130 logger_sublogger_pairname_ptr->second.c_str());
131 delete logger_sublogger_pairname_ptr;
143 rcutils_ret_t rcutils_ret = rcutils_logging_set_logger_level(
145 static_cast<RCUTILS_LOG_SEVERITY
>(level));
146 if (rcutils_ret != RCUTILS_RET_OK) {
147 if (rcutils_ret == RCUTILS_RET_INVALID_ARGUMENT) {
148 exceptions::throw_from_rcl_error(
150 rcutils_get_error_state(), rcutils_reset_error);
152 exceptions::throw_from_rcl_error(
154 rcutils_get_error_state(), rcutils_reset_error);
161 int logger_level = rcutils_logging_get_logger_effective_level(
get_name());
163 if (logger_level < 0) {
164 exceptions::throw_from_rcl_error(
166 rcutils_get_error_state(), rcutils_reset_error);
169 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 rcpputils::fs::path get_logging_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.