rclcpp  master
C++ ROS Client Library API
logger.hpp
Go to the documentation of this file.
1 // Copyright 2017 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RCLCPP__LOGGER_HPP_
16 #define RCLCPP__LOGGER_HPP_
17 
18 #include <memory>
19 #include <string>
20 
22 
23 #include "rcl/node.h"
24 #include "rcutils/logging.h"
25 #include "rcpputils/filesystem_helper.hpp"
26 
36 // TODO(dhood): determine this automatically from `RCLCPP_LOG_MIN_SEVERITY`
37 #ifndef RCLCPP_LOGGING_ENABLED
38 #define RCLCPP_LOGGING_ENABLED 1
39 #endif
40 
41 namespace rclcpp
42 {
43 
44 // Forward declaration is used for friend statement.
45 namespace node_interfaces
46 {
47 class NodeLogging;
48 }
49 
50 class Logger;
51 
53 
64 Logger
65 get_logger(const std::string & name);
66 
68 
76 Logger
77 get_node_logger(const rcl_node_t * node);
78 
80 
88 rcpputils::fs::path
90 
91 class Logger
92 {
93 public:
95  enum class Level
96  {
103  };
104 
105 private:
106  friend Logger rclcpp::get_logger(const std::string & name);
107  friend ::rclcpp::node_interfaces::NodeLogging;
108 
110 
114  Logger()
115  : name_(nullptr) {}
116 
118 
121  explicit Logger(const std::string & name)
122  : name_(new std::string(name)) {}
123 
125 
126 public:
128  Logger(const Logger &) = default;
129 
131 
137  const char *
138  get_name() const
139  {
140  if (!name_) {
141  return nullptr;
142  }
143  return name_->c_str();
144  }
145 
147 
159  Logger
160  get_child(const std::string & suffix)
161  {
162  if (!name_) {
163  return Logger();
164  }
165  return Logger(*name_ + "." + suffix);
166  }
167 
169 
175  void
176  set_level(Level level);
177 };
178 
179 } // namespace rclcpp
180 
181 #endif // RCLCPP__LOGGER_HPP_
rcl_node_t
std::string
std::shared_ptr< const std::string >
rclcpp::Logger::Level::Debug
@ Debug
The debug log level.
rclcpp::get_logger
Logger get_logger(const std::string &name)
Return a named logger.
RCUTILS_LOG_SEVERITY_DEBUG
RCUTILS_LOG_SEVERITY_DEBUG
rclcpp::get_logging_directory
rcpputils::fs::path get_logging_directory()
Get the current logging directory.
rclcpp::Logger::Level::Error
@ Error
The error log level.
rclcpp::Logger::Level
Level
An enum for the type of logger level.
Definition: logger.hpp:95
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
RCLCPP_PUBLIC
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
RCUTILS_LOG_SEVERITY_INFO
RCUTILS_LOG_SEVERITY_INFO
rclcpp::Logger
Definition: logger.hpp:91
rclcpp::Logger::get_name
const char * get_name() const
Get the name of this logger.
Definition: logger.hpp:138
rclcpp::Logger::Level::Info
@ Info
The info log level.
RCUTILS_LOG_SEVERITY_UNSET
RCUTILS_LOG_SEVERITY_UNSET
RCUTILS_LOG_SEVERITY_FATAL
RCUTILS_LOG_SEVERITY_FATAL
rclcpp::get_node_logger
Logger get_node_logger(const rcl_node_t *node)
Return a named logger using an rcl_node_t.
rclcpp::Logger::set_level
void set_level(Level level)
Set level for current logger.
visibility_control.hpp
std
node.h
rclcpp::Logger::get_child
Logger get_child(const std::string &suffix)
Return a logger that is a descendant of this logger.
Definition: logger.hpp:160
RCUTILS_LOG_SEVERITY_ERROR
RCUTILS_LOG_SEVERITY_ERROR
rclcpp::Logger::Level::Fatal
@ Fatal
The fatal log level.
RCUTILS_LOG_SEVERITY_WARN
RCUTILS_LOG_SEVERITY_WARN
rclcpp::Logger::Level::Warn
@ Warn
The warn log level.
logging.h
rclcpp::Logger::Level::Unset
@ Unset
The unset log level.