synchros2.logging module

class synchros2.logging.MemoizingRcutilsLogger[source]

Bases: object

An alternative, more efficient implementation of RcutilsLogger.

MemoizingRcutilsLogger caches logging call configuration to speed up subsequent invocations.

__init__(raw_logger: rclpy.impl.rcutils_logger.RcutilsLogger) None[source]

Initializes the logger with the given name, or the root logger if none is provided.

debug(message: str, origin: Traceback | None = None, **kwargs: Any) bool[source]

Log a message with DEBUG severity via :py:method:MemoizingRcutilsLogger.log:.

error(message: str, origin: Traceback | None = None, **kwargs: Any) bool[source]

Log a message with ERROR severity via :py:method:MemoizingRcutilsLogger.log:.

fatal(message: str, origin: Traceback | None = None, **kwargs: Any) bool[source]

Log a message with FATAL severity via :py:method:MemoizingRcutilsLogger.log:.

get_child(name: str) MemoizingRcutilsLogger[source]

Gets a child logger with the given name.

get_effective_level() rclpy.logging.LoggingSeverity[source]

Gets the effective logger severity level.

The effective severity level of a logger is the first severity level set in the logger genealogy (ie. its own or that of its parent or that of its grandparent and so on), or the default severity level when no severity level is.

info(message: str, origin: Traceback | None = None, **kwargs: Any) bool[source]

Log a message with INFO severity via :py:method:MemoizingRcutilsLogger.log:.

is_enabled_for(level: int | rclpy.logging.LoggingSeverity) bool[source]

Checks whether the logger is enabled for logs at the given severity level.

log(message: str, level: int | rclpy.logging.LoggingSeverity, origin: Traceback | None = None, throttle_duration_sec: float | None = None, throttle_time_source_type: rclpy.clock.Clock | None = None, skip_first: bool | None = None, once: bool | None = None) bool[source]

Log a message with the specified severity level.

A message will not be logged if:

  • the logger is not enabled for the logging function’s severity level (i.e. it is less than the severity level of the logger), or

  • some logging filter (throttling, once, skip) causes the message to be skipped.

Logging filters will only be evaluated if the logger is enabled for the logging function’s severity level.

Parameters:
  • message – message to be logged.

  • level – severity level of the message.

  • origin – optional log call site, defaults to the caller one level up the call stack.

  • throttle_duration_sec – optional period for throttling, in seconds.

  • throttle_time_source_type – optional time source for throttling, defaults to system time.

  • skip_first – if True, skip the first log.

  • once – if True, only log once.

Returns:

whether the message was logged or not.

property name: str

Gets the logger name.

set_level(level: int | rclpy.logging.LoggingSeverity) None[source]

Sets logger severity level.

warn(message: str, origin: Traceback | None = None, **kwargs: Any) bool[source]

Log a message with WARN severity via :py:method:MemoizingRcutilsLogger.log:.

Deprecated in favor of :py:classmethod:RcutilsLogger.warning:.

warning(message: str, origin: Traceback | None = None, **kwargs: Any) bool[source]

Log a message with WARN severity via :py:method:MemoizingRcutilsLogger.log:.

class synchros2.logging.RcutilsLogHandler[source]

Bases: Handler

A logging.Handler subclass to forward log records to the ROS 2 logging system.

__init__(node_or_logger: rclpy.impl.rcutils_logger.RcutilsLogger | MemoizingRcutilsLogger | rclpy.node.Node, level: int | str = 0) None[source]

Constructor

default_formatter = <logging.Formatter object>
emit(record: LogRecord) None[source]

Do whatever it takes to actually log the specified logging record.

setLevel(level: int | str) None[source]

Sets the threshold for this handler to level.

Logging messages which are less severe than level will be ignored. When a handler is created, the level is set to NOTSET (which causes all messages to be processed).

synchros2.logging.as_memoizing_logger(logger: rclpy.impl.rcutils_logger.RcutilsLogger) MemoizingRcutilsLogger[source]

Turns a regular rclpy logger into a memoizing one.

synchros2.logging.logs_to_ros(node: rclpy.node.Node, name: str | None = None, level: int | None = None, propagate: bool | None = None) Iterator[None][source]

Forwards Python logging logs to the ROS 2 logging system.

Note that logs are subject to severity level thresholds and propagation semantics at both the logging module and the ROS 2 logging system. For instance, for an informational log made from a non-root logging logger to find its way to a ROS 2 logging system sink like the /rosout topic:

  • the entire logging hierarchy all the way up to the root logger, and the ROS 2 node logger must be configured with a severity level at or below INFO;

  • and the logging hierarchy must be configured to propagate logs (true by default).

Parameters:
  • node – a ROS 2 node, necessary for rosout logging (if enabled).

  • name – optional name of the logger to attach to (on both logging systems), defaults to the root logger.

  • level – optional severity level threshold to set on both logging systems, defaults to keeping the current (effective) level of the ROS 2 logger.

  • propagate – optional override for logging propagation semantics.

synchros2.logging.make_logging_function(name: str, level: rclpy.logging.LoggingSeverity, origin: Traceback, throttle_duration_sec: float | None = None, throttle_time_source: rclpy.clock.Clock | None = None, skip_first: bool | None = None, once: bool | None = None) Callable[[str], bool][source]

Make a fast rclpy logging function.

A logging function takes a log message and returns True if the message was logged, False otherwise. A message will not be logged if:

  • the logger is not enabled for the logging function’s severity level (i.e. it is less than the severity level of the logger), or

  • some logging filter (throttling, once, skip) causes the message to be skipped.

Logging filters will only be evaluated if the logger is enabled for the logging function’s severity level.

Parameters:
  • name – logger name.

  • level – log severity level.

  • origin – log call site.

  • throttle_duration_sec – optional period for throttling, in seconds.

  • throttle_time_source – optional time source for throttling, defaults to system time.

  • skip_first – if True, skip the first log.

  • once – if True, only log once.

Returns:

a logging function.