|
| 1 | +// Copyright 2023 Tier IV, 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 | +// =============== Note =============== |
| 16 | +// This is a util class implementation of the logger_config_component provided by ROS 2 |
| 17 | +// https://github.com/ros2/demos/blob/humble/logging_demo/src/logger_config_component.cpp |
| 18 | +// |
| 19 | +// When ROS 2 officially supports the set_logger_level option in release version, this class can be |
| 20 | +// removed. |
| 21 | +// https://github.com/ros2/ros2/issues/1355 |
| 22 | + |
| 23 | +// =============== How to use =============== |
| 24 | +// ___In your_node.hpp___ |
| 25 | +// #include "autoware/universe_utils/ros/logger_level_configure.hpp" |
| 26 | +// class YourNode : public rclcpp::Node { |
| 27 | +// ... |
| 28 | +// |
| 29 | +// // Define logger_configure as a node class member variable |
| 30 | +// std::unique_ptr<autoware::universe_utils::LoggerLevelConfigure> logger_configure_; |
| 31 | +// } |
| 32 | +// |
| 33 | +// ___In your_node.cpp___ |
| 34 | +// YourNode::YourNode() { |
| 35 | +// ... |
| 36 | +// |
| 37 | +// // Set up logger_configure |
| 38 | +// logger_configure_ = std::make_unique<LoggerLevelConfigure>(this); |
| 39 | +// } |
| 40 | + |
| 41 | +#ifndef AUTOWARE_UTILS_LOGGING__LOGGER_LEVEL_CONFIGURE_HPP_ |
| 42 | +#define AUTOWARE_UTILS_LOGGING__LOGGER_LEVEL_CONFIGURE_HPP_ |
| 43 | + |
| 44 | +#include <logging_demo/srv/config_logger.hpp> |
| 45 | +#include <rclcpp/rclcpp.hpp> |
| 46 | + |
| 47 | +namespace autoware_utils_logging |
| 48 | +{ |
| 49 | + |
| 50 | +class LoggerLevelConfigure |
| 51 | +{ |
| 52 | +private: |
| 53 | + using ConfigLogger = logging_demo::srv::ConfigLogger; |
| 54 | + |
| 55 | +public: |
| 56 | + explicit LoggerLevelConfigure(rclcpp::Node * node); |
| 57 | + |
| 58 | +private: |
| 59 | + rclcpp::Logger ros_logger_; |
| 60 | + rclcpp::Service<ConfigLogger>::SharedPtr srv_config_logger_; |
| 61 | + |
| 62 | + void on_logger_config_service( |
| 63 | + const ConfigLogger::Request::SharedPtr request, |
| 64 | + const ConfigLogger::Response::SharedPtr response); |
| 65 | +}; |
| 66 | + |
| 67 | +} // namespace autoware_utils_logging |
| 68 | + |
| 69 | +#endif // AUTOWARE_UTILS_LOGGING__LOGGER_LEVEL_CONFIGURE_HPP_ |
0 commit comments