Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(autoware_utils_logging): split package #37

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion autoware_utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ The ROS module provides utilities for working with ROS messages and nodes:

- **`debug_publisher.hpp`**: A helper class for publishing debug messages with timestamps.
- **`diagnostics_interface.hpp`**: An interface for publishing diagnostic messages.
- **`logger_level_configure.hpp`**: Utility for configuring logger levels dynamically.
- **`msg_covariance.hpp`**: Indices for accessing covariance matrices in ROS messages.
- **`msg_operation.hpp`**: Overloaded operators for quaternion messages.
- **`parameter.hpp`**: Simplifies parameter retrieval and declaration.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Tier IV, Inc.
// Copyright 2025 The Autoware Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,57 +12,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// =============== Note ===============
// This is a util class implementation of the logger_config_component provided by ROS 2
// https://github.com/ros2/demos/blob/humble/logging_demo/src/logger_config_component.cpp
//
// When ROS 2 officially supports the set_logger_level option in release version, this class can be
// removed.
// https://github.com/ros2/ros2/issues/1355

// =============== How to use ===============
// ___In your_node.hpp___
// #include "autoware/universe_utils/ros/logger_level_configure.hpp"
// class YourNode : public rclcpp::Node {
// ...
//
// // Define logger_configure as a node class member variable
// std::unique_ptr<autoware::universe_utils::LoggerLevelConfigure> logger_configure_;
// }
//
// ___In your_node.cpp___
// YourNode::YourNode() {
// ...
//
// // Set up logger_configure
// logger_configure_ = std::make_unique<LoggerLevelConfigure>(this);
// }

#ifndef AUTOWARE_UTILS__ROS__LOGGER_LEVEL_CONFIGURE_HPP_
#define AUTOWARE_UTILS__ROS__LOGGER_LEVEL_CONFIGURE_HPP_

#include "logging_demo/srv/config_logger.hpp"

#include <rclcpp/rclcpp.hpp>

namespace autoware_utils
{
class LoggerLevelConfigure
{
private:
using ConfigLogger = logging_demo::srv::ConfigLogger;

public:
explicit LoggerLevelConfigure(rclcpp::Node * node);
// NOLINTBEGIN(build/namespaces, whitespace/line_length)
// clang-format off

private:
rclcpp::Logger ros_logger_;
rclcpp::Service<ConfigLogger>::SharedPtr srv_config_logger_;
#pragma message("#include <autoware_utils/ros/logger_level_configure.hpp> is deprecated. Use #include <autoware_utils_logging/logger_level_configure.hpp> instead.")
#include <autoware_utils_logging/logger_level_configure.hpp>
namespace autoware_utils { using namespace autoware_utils_logging; }

void on_logger_config_service(
const ConfigLogger::Request::SharedPtr request,
const ConfigLogger::Response::SharedPtr response);
};
// clang-format on
// NOLINTEND

} // namespace autoware_utils
#endif // AUTOWARE_UTILS__ROS__LOGGER_LEVEL_CONFIGURE_HPP_
2 changes: 1 addition & 1 deletion autoware_utils/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<depend>autoware_perception_msgs</depend>
<depend>autoware_planning_msgs</depend>
<depend>autoware_utils_geometry</depend>
<depend>autoware_utils_logging</depend>
<depend>autoware_utils_math</depend>
<depend>autoware_utils_pcl</depend>
<depend>autoware_utils_visualization</depend>
Expand All @@ -28,7 +29,6 @@
<depend>diagnostic_msgs</depend>
<depend>geometry_msgs</depend>
<depend>libboost-system-dev</depend>
<depend>logging_demo</depend>
<depend>rclcpp</depend>
<depend>tf2</depend>
<depend>tf2_eigen</depend>
Expand Down
19 changes: 19 additions & 0 deletions autoware_utils_logging/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.14)
project(autoware_utils_logging)

find_package(autoware_cmake REQUIRED)
autoware_package()

ament_auto_add_library(${PROJECT_NAME} SHARED
"src/logger_level_configure.cpp"
)

if(BUILD_TESTING)
ament_add_ros_isolated_gtest(test_${PROJECT_NAME}
"test/main.cpp"
"test/cases/logger_level_configure.cpp"
)
target_link_libraries(test_${PROJECT_NAME} ${PROJECT_NAME})
endif()

ament_auto_package()
11 changes: 11 additions & 0 deletions autoware_utils_logging/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# autoware_utils_logging

## Overview

The **autoware_utils** library is a comprehensive toolkit designed to facilitate the development of autonomous driving applications.
This package provides essential utilities for logging.
It is extensively used in the Autoware project to handle common tasks such as configuring logger levels.

## Design

- **`logger_level_configure.hpp`**: Utility for configuring logger levels dynamically.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2023 Tier IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// =============== Note ===============
// This is a util class implementation of the logger_config_component provided by ROS 2
// https://github.com/ros2/demos/blob/humble/logging_demo/src/logger_config_component.cpp
//
// When ROS 2 officially supports the set_logger_level option in release version, this class can be
// removed.
// https://github.com/ros2/ros2/issues/1355

// =============== How to use ===============
// ___In your_node.hpp___
// #include "autoware/universe_utils/ros/logger_level_configure.hpp"
// class YourNode : public rclcpp::Node {
// ...
//
// // Define logger_configure as a node class member variable
// std::unique_ptr<autoware::universe_utils::LoggerLevelConfigure> logger_configure_;
// }
//
// ___In your_node.cpp___
// YourNode::YourNode() {
// ...
//
// // Set up logger_configure
// logger_configure_ = std::make_unique<LoggerLevelConfigure>(this);
// }

#ifndef AUTOWARE_UTILS_LOGGING__LOGGER_LEVEL_CONFIGURE_HPP_
#define AUTOWARE_UTILS_LOGGING__LOGGER_LEVEL_CONFIGURE_HPP_

#include <logging_demo/srv/config_logger.hpp>
#include <rclcpp/rclcpp.hpp>

namespace autoware_utils_logging
{

class LoggerLevelConfigure
{
private:
using ConfigLogger = logging_demo::srv::ConfigLogger;

public:
explicit LoggerLevelConfigure(rclcpp::Node * node);

private:
rclcpp::Logger ros_logger_;
rclcpp::Service<ConfigLogger>::SharedPtr srv_config_logger_;

void on_logger_config_service(
const ConfigLogger::Request::SharedPtr request,
const ConfigLogger::Response::SharedPtr response);
};

} // namespace autoware_utils_logging

#endif // AUTOWARE_UTILS_LOGGING__LOGGER_LEVEL_CONFIGURE_HPP_
27 changes: 27 additions & 0 deletions autoware_utils_logging/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>autoware_utils_logging</name>
<version>1.1.0</version>
<description>The autoware_utils_logging package</description>
<maintainer email="egon.kang@autocore.ai">Jian Kang</maintainer>
<maintainer email="ryohsuke.mitsudome@tier4.jp">Ryohsuke Mitsudome</maintainer>
<maintainer email="esteve.fernandez@tier4.jp">Esteve Fernandez</maintainer>
<maintainer email="yutaka.kondo@tier4.jp">Yutaka Kondo</maintainer>
<maintainer email="isamu.takagi@tier4.jp">Takagi, Isamu</maintainer>
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>
<buildtool_depend>autoware_cmake</buildtool_depend>

<depend>logging_demo</depend>
<depend>rclcpp</depend>

<test_depend>ament_cmake_ros</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>autoware_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "autoware_utils/ros/logger_level_configure.hpp"
#include "autoware_utils_logging/logger_level_configure.hpp"

#include <rcutils/logging.h>

namespace autoware_utils
namespace autoware_utils_logging
{

LoggerLevelConfigure::LoggerLevelConfigure(rclcpp::Node * node) : ros_logger_(node->get_logger())
{
using std::placeholders::_1;
Expand Down Expand Up @@ -58,4 +59,4 @@ void LoggerLevelConfigure::on_logger_config_service(
return;
}

} // namespace autoware_utils
} // namespace autoware_utils_logging
38 changes: 38 additions & 0 deletions autoware_utils_logging/test/cases/logger_level_configure.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2025 The Autoware Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "autoware_utils_logging/logger_level_configure.hpp"

#include <gtest/gtest.h>

#include <memory>

class LoggerLevelConfigureNode : public rclcpp::Node
{
public:
using LoggerLevelConfigure = autoware_utils_logging::LoggerLevelConfigure;

LoggerLevelConfigureNode() : rclcpp::Node("__auto__")
{
logger_configure_ = std::make_unique<LoggerLevelConfigure>(this);
}

private:
std::unique_ptr<LoggerLevelConfigure> logger_configure_;
};

TEST(TestLoggerLevelConfigure, Instantiation)
{
const auto node = std::make_shared<LoggerLevelConfigureNode>();
}
36 changes: 36 additions & 0 deletions autoware_utils_logging/test/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2025 The Autoware Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <rclcpp/rclcpp.hpp>

#include <gtest/gtest.h>

class RclcppEnvironment : public testing::Environment
{
public:
RclcppEnvironment(int argc, char ** argv) : argc(argc), argv(argv) {}
void SetUp() override { rclcpp::init(argc, argv); }
void TearDown() override { rclcpp::shutdown(); }

private:
int argc;
char ** argv;
};

int main(int argc, char ** argv)
{
testing::InitGoogleTest(&argc, argv);
testing::AddGlobalTestEnvironment(new RclcppEnvironment(argc, argv));
return RUN_ALL_TESTS();
}