Skip to content

Commit 9c117dc

Browse files
committed
fix(opcua,#386): use rcutils logging API for Humble compat
``rclcpp::Logger::get_effective_level`` was added in Jazzy; Humble ``Unit tests (humble)`` job on PR #387 fails with ``'class rclcpp::Logger' has no member named 'get_effective_level'`` against Jazzy+ headers. Switch the three pre-gate helpers (``client_debug_enabled``, ``poller_debug_enabled``, ``plugin_debug_enabled``) to ``rcutils_logging_logger_is_enabled_for(name, severity)``, which is present in rcutils on Humble through Rolling. Functionally identical - the rclcpp method is just a thin wrapper around the rcutils call. Add ``<rcutils/logging.h>`` include to all three .cpp files. No public API change; named loggers (``opcua.client`` / ``opcua.poller`` / ``opcua.plugin``) and DEBUG behaviour stay identical. Local verify (Jazzy): 27/27 test_opcua_client. Humble CI gate is the proof.
1 parent 12b0764 commit 9c117dc

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

src/ros2_medkit_plugins/ros2_medkit_opcua/src/opcua_client.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <open62541/client_subscriptions.h>
2828
#include <open62541/types.h>
2929
#include <rclcpp/logging.hpp>
30+
#include <rcutils/logging.h>
3031

3132
namespace ros2_medkit_gateway {
3233

@@ -43,10 +44,10 @@ inline rclcpp::Logger opcua_client_logger() {
4344
// Pre-gate for traces whose stream-build cost is non-trivial (e.g. per-arg
4445
// loops). RCLCPP_DEBUG_STREAM constructs the std::stringstream
4546
// unconditionally, so for hot paths we check the effective level first.
46-
// ``Level`` is an enum class - cast to int for the ordered comparison.
47+
// Uses the rcutils-level API (available in Humble through Rolling) instead
48+
// of rclcpp::Logger::get_effective_level (Jazzy+ only).
4749
inline bool client_debug_enabled() {
48-
return static_cast<int>(opcua_client_logger().get_effective_level()) <=
49-
static_cast<int>(rclcpp::Logger::Level::Debug);
50+
return rcutils_logging_logger_is_enabled_for("opcua.client", RCUTILS_LOG_SEVERITY_DEBUG);
5051
}
5152
} // namespace
5253

src/ros2_medkit_plugins/ros2_medkit_opcua/src/opcua_plugin.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "ros2_medkit_opcua/opcua_plugin.hpp"
1616

1717
#include <rclcpp/rclcpp.hpp>
18+
#include <rcutils/logging.h>
1819
#include <ros2_medkit_msgs/msg/fault.hpp>
1920
#include <ros2_medkit_msgs/srv/clear_fault.hpp>
2021
#include <ros2_medkit_msgs/srv/report_fault.hpp>
@@ -42,8 +43,9 @@ inline rclcpp::Logger opcua_plugin_logger() {
4243
}
4344

4445
inline bool plugin_debug_enabled() {
45-
return static_cast<int>(opcua_plugin_logger().get_effective_level()) <=
46-
static_cast<int>(rclcpp::Logger::Level::Debug);
46+
// rcutils API for Humble compatibility; Jazzy+ adds rclcpp::Logger::
47+
// get_effective_level but Humble does not.
48+
return rcutils_logging_logger_is_enabled_for("opcua.plugin", RCUTILS_LOG_SEVERITY_DEBUG);
4749
}
4850

4951
/// Parse a JSON "value" field, coerce to the node's declared data_type, and

src/ros2_medkit_plugins/ros2_medkit_opcua/src/opcua_poller.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <open62541/types.h>
2626
#include <rclcpp/logging.hpp>
27+
#include <rcutils/logging.h>
2728

2829
namespace ros2_medkit_gateway {
2930

@@ -34,8 +35,9 @@ inline rclcpp::Logger opcua_poller_logger() {
3435
}
3536

3637
inline bool poller_debug_enabled() {
37-
return static_cast<int>(opcua_poller_logger().get_effective_level()) <=
38-
static_cast<int>(rclcpp::Logger::Level::Debug);
38+
// rcutils API for Humble compatibility; Jazzy+ adds rclcpp::Logger::
39+
// get_effective_level but Humble does not.
40+
return rcutils_logging_logger_is_enabled_for("opcua.poller", RCUTILS_LOG_SEVERITY_DEBUG);
3941
}
4042
} // namespace
4143

0 commit comments

Comments
 (0)