RosLogger¶
Inherits: RefCounted
A named ROS 2 logger, with the same API as rclpy's logger.
Description¶
RosLogger writes messages through the ROS 2 logging system, so they get the standard severity formatting, honour --ros-args --log-level and RCUTILS_CONSOLE_OUTPUT_FORMAT, and can be inspected with ROS tooling. Its API mirrors rclpy's logger: debug(), info(), warning(), error() and fatal() take the message and an optional Dictionary standing in for rclpy's keyword arguments.
It cannot be created with new(); get one from RosNode.get_logger() (published on /rosout), from get_child(), or from rclgd.get_logger() (console only, no node needed).
var logger := ros_node.get_logger()
logger.info("Simulation started")
logger.warning("Wheel slip detected", {"throttle_duration_sec": 1.0})
logger.debug("First contact", {"once": true})
var lidar_logger := logger.get_child("lidar")
lidar_logger.set_level(RosLogger.DEBUG)
Filters: The keyword dictionary accepts once (log only the first time), skip_first (skip the first time) and throttle_duration_sec (log at most once per period, measured on a steady clock). once cannot be combined with the others. As in rclpy, filter state is kept per call site, so the same line is throttled independently of other lines. Script call stacks are not tracked in release exports unless debug/settings/gdscript/always_track_call_stacks is enabled; filters then key on the message text instead (with a one-time warning), and log locations are omitted.
Properties¶
Methods¶
debug(message: String, kwargs: Dictionary = {}) |
|
error(message: String, kwargs: Dictionary = {}) |
|
fatal(message: String, kwargs: Dictionary = {}) |
|
get_effective_level() const |
|
info(message: String, kwargs: Dictionary = {}) |
|
is_enabled_for(severity: LoggingSeverity) const |
|
log(message: String, severity: LoggingSeverity, kwargs: Dictionary = {}) |
|
void |
set_level(level: LoggingSeverity) |
warning(message: String, kwargs: Dictionary = {}) |
Enumerations¶
enum LoggingSeverity: 🔗
LoggingSeverity UNSET = 0
No level set; the logger inherits its level from its ancestors.
LoggingSeverity DEBUG = 10
Debug severity.
LoggingSeverity INFO = 20
Info severity. This is the default level.
LoggingSeverity WARN = 30
Warning severity.
LoggingSeverity ERROR = 40
Error severity.
LoggingSeverity FATAL = 50
Fatal severity.
Property Descriptions¶
String get_name()
The logger's fully qualified name, e.g. my_node or my_node.lidar. Read-only.
Method Descriptions¶
bool debug(message: String, kwargs: Dictionary = {}) 🔗
Logs message at DEBUG severity. See log() for kwargs and the return value.
bool error(message: String, kwargs: Dictionary = {}) 🔗
Logs message at ERROR severity. See log() for kwargs and the return value.
bool fatal(message: String, kwargs: Dictionary = {}) 🔗
Logs message at FATAL severity. See log() for kwargs and the return value.
RosLogger get_child(name: String) const 🔗
Returns a child logger named <this logger's name>.<name>. Its level can be set independently, and it inherits this logger's level while unset. A child of a node's logger is also published on /rosout. name must not be empty.
LoggingSeverity get_effective_level() const 🔗
Returns the severity threshold this logger actually uses: its own level if set, otherwise the nearest ancestor's, otherwise the default level (INFO unless changed).
bool info(message: String, kwargs: Dictionary = {}) 🔗
Logs message at INFO severity. See log() for kwargs and the return value.
bool is_enabled_for(severity: LoggingSeverity) const 🔗
Returns true if a message of severity would be emitted by this logger. Use it to skip building expensive messages.
bool log(message: String, severity: LoggingSeverity, kwargs: Dictionary = {}) 🔗
Logs message at severity, which must be DEBUG, INFO, WARN, ERROR or FATAL. kwargs takes the optional filters once, skip_first and throttle_duration_sec (see the class description). Any other key, or a value of the wrong type, is an error.
Returns true if the message was emitted, and false if it was below the logger's level or suppressed by a filter.
void set_level(level: LoggingSeverity) 🔗
Sets the minimum severity this logger emits. Pass UNSET to inherit the level from its ancestors again. Equivalent to --ros-args --log-level <name>:=<level>.
bool warning(message: String, kwargs: Dictionary = {}) 🔗
Logs message at WARN severity. See log() for kwargs and the return value.