19 #include "rcl_logging_interface/rcl_logging_interface.h"
20 #include "rcl/error_handling.h"
23 #include "rclcpp/exceptions.hpp"
24 #include "rclcpp/logger.hpp"
25 #include "rclcpp/logging.hpp"
27 #include "./logging_mutex.hpp"
35 #if RCLCPP_LOGGING_ENABLED
47 if (
nullptr == logger_name) {
50 logger,
"failed to get logger name from node at address %p",
51 static_cast<void *
>(
const_cast<rcl_node_t *
>(node)));
60 char * log_dir = NULL;
61 auto allocator = rcutils_get_default_allocator();
62 rcl_logging_ret_t ret = rcl_logging_get_logging_directory(allocator, &log_dir);
63 if (RCL_LOGGING_RET_OK != ret) {
64 rclcpp::exceptions::throw_from_rcl_error(ret);
66 std::string path{log_dir};
67 allocator.deallocate(log_dir, allocator.state);
79 std::shared_ptr<std::recursive_mutex> logging_mutex;
80 logging_mutex = get_global_logging_mutex();
82 std::lock_guard<std::recursive_mutex> guard(*logging_mutex);
87 exceptions::throw_from_rcl_error(
88 rcl_ret,
"failed to call rcl_logging_rosout_add_sublogger",
89 rcl_get_error_state(), rcl_reset_error);
93 Logger logger(*name_ + RCUTILS_LOGGING_SEPARATOR_STRING + suffix);
95 logger.logger_sublogger_pairname_.reset(
96 new std::pair<std::string, std::string>({*name_, suffix}),
97 [logging_mutex](std::pair<std::string, std::string> * logger_sublogger_pairname_ptr) {
98 std::lock_guard<std::recursive_mutex> guard(*logging_mutex);
100 logger_sublogger_pairname_ptr->first.c_str(),
101 logger_sublogger_pairname_ptr->second.c_str());
102 delete logger_sublogger_pairname_ptr;
114 rcutils_ret_t rcutils_ret = rcutils_logging_set_logger_level(
116 static_cast<RCUTILS_LOG_SEVERITY
>(level));
117 if (rcutils_ret != RCUTILS_RET_OK) {
118 if (rcutils_ret == RCUTILS_RET_INVALID_ARGUMENT) {
119 exceptions::throw_from_rcl_error(
121 rcutils_get_error_state(), rcutils_reset_error);
123 exceptions::throw_from_rcl_error(
125 rcutils_get_error_state(), rcutils_reset_error);
132 int logger_level = rcutils_logging_get_logger_effective_level(
get_name());
134 if (logger_level < 0) {
135 exceptions::throw_from_rcl_error(
137 rcutils_get_error_state(), rcutils_reset_error);
140 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 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.