天天看點

ROS2程式設計基礎課程--日志

課程補充參考資料:https://download.csdn.net/download/zhangrelay/11751608

Logging and logger configuration 

日志記錄和日志記錄器配置

Table of Contents 目錄

Overview 概叙

Logger concepts 日志記錄器概念

Logging usage 日志記錄用法

Logger configuration 日志記錄器配置

Command line configuration of the default severity level 預設嚴重性級别的指令行配置

Programmatic configuration of individual loggers 單個記錄器的程式設計配置

Console output configuration 控制台輸出配置

The logging functionality currently supported is: 目前支援的日志記錄功能是:

Client libraries (rclcpp and rclpy) using a common logging library to provide: 

用戶端庫(rclcpp和rclpy)使用通用日志記錄庫來提供:

Log calls with a variety of filters. 

使用各種過濾器記錄調用。

Hierarchy of loggers. 

記錄器的層次結構。

Loggers associated with nodes that automatically use the node’s name and namespace. 

與自動使用節點名稱和命名空間的節點關聯的記錄器。

Console output. 

控制台輸出。

File output and functionality akin to rosout for remote consumption of messages is forthcoming. 

檔案輸出和功能類似于用于遠端消費消息的rosout即将釋出。

Programmatic configuration of logger levels. 

記錄器級别的程式設計配置。

Launch-time configuration of the default logger level is supported; config files and external configuration at run-time is forthcoming. 

支援預設記錄器級别的啟動時配置; 即将在運作時配置檔案和外部配置。

[INFO] [turtlesim]: Starting turtlesim with node name /turtlesim

[INFO] [turtlesim]: Spawning turtle [turtle1] at x=[5.544445], y=[5.544445], theta=[0.000000]

[WARN] [turtlesim]: Oh no! I hit the wall! (Clamping from [x=11.112445, y=5.544445])

[WARN] [turtlesim]: Oh no! I hit the wall! (Clamping from [x=11.120889, y=5.544445])

Log messages have a severity level associated with them: DEBUG, INFO, WARN, ERROR or FATAL, in ascending order. 

日志消息與其相關聯的嚴重性級别:DEBUG,INFO,WARN,ERROR或者FATAL,按升序排列。

A logger will only process log messages with severity at or higher than a specified level chosen for the logger. 

記錄器僅處理嚴重性等于或高于為日志記錄器選擇的指定級别的日志消息。

Each node (in rclcpp and rclpy) has a logger associated with it that automatically includes the node’s name and namespace. If the node’s name is externally remapped to something other than what is defined in the source code, it will be reflected in the logger name. Non-node loggers can also be created that use a specific name. 

每個節點(如 rclcpp和rclpy)都有一個與之關聯的記錄器,它自動包含節點的名稱和名稱空間。如果節點的名稱從外部重新映射到源代碼中定義的名稱以外的其他名稱,則它将反映在記錄器名稱中。還可以建立使用特定名稱的非節點記錄器。

Logger names represent a hierarchy. If the level of a logger named “abc.def” is unset, it will defer to the level of its parent named “abc”, and if that level is also unset, the default logger level will be used. When the level of logger “abc” is changed, all of its descendants (e.g. “abc.def”, “abc.ghi.jkl”) will have their level impacted unless their level has been explicitly set. 

日志記錄器名稱表示層次結構。如果未設定名為“abc.def”的記錄器的級别,它将推遲到其名為“abc”的父級别,如果該級别也未設定,則将使用預設記錄器級别。當記錄器“abc”的級别改變時,其所有後代(例如“abc.def”,“abc.ghi.jkl”)将對其級别産生影響,除非已明确設定其級别。

In C++: 在C ++中:

See the logging demo for example usage. 

有關示例用法,請參考日志記錄示範

See the rclcpp documentation for an extensive list of functionality. 

有關功能的詳盡清單,請參考rclcpp文檔。

In Python: 在Python中:

See the rclpy examples for example usage of a node’s logger. 

有關節點記錄器的示例用法,請參考rclpy示例。

See the rclpy tests for example usage of keyword arguments (e.g. skip_first, once). 

有關關鍵字參數的使用示例,請參考rclpy測試(例如skip_first,once)。

As of the Bouncy ROS 2 release, the default severity level for loggers can be configured from the command line with the following, for example (the level string is not case sensitive):  

從Bouncy ROS 2及以後的版本開始,可以從指令行配置記錄器的預設嚴重性級别,例如:

(級别字元串不區分大小寫)

ros2 run demo_nodes_cpp listener _log_level:=debug

This will affect all loggers that have not explicitly been configured to use a particular severity level. Configuration of specific loggers from the command line is forthcoming. 

這将影響未明确配置為使用特定嚴重性級别的所有記錄器。即将從指令行配置特定記錄器。

Logger configuration is still under development. For now, the severity level of individual loggers can be configured programmatically with, e.g.: 

記錄器配置仍在開發中。目前,可以通過程式設計方式配置各個記錄器的嚴重性級别,例如:

rcutils_logging_set_logger_level("logger_name", RCUTILS_LOG_SEVERITY_DEBUG);

logger.set_level(rclpy.logging.LoggingSeverity.DEBUG)

rclpy.logging.set_logger_level('logger_name', rclpy.logging.LoggingSeverity.DEBUG)

The logging demo provides an example of manually exposing a service so that loggers can be configured externally; in the future we expect runtime configuration capabilities of loggers to be exposed automatically. 

所述日志記錄示範提供的手動開發服務,使得記錄器可從外部配置; 在未來,希望記錄器的運作時配置功能能夠自動公開。

By default, console output will be formatted to include the message severity, logger name, and the message. Information such as the file name, function name and line number of the log call are also available. Custom console output format can be configured with the RCUTILS_CONSOLE_OUTPUT_FORMAT environment variable: see the rcutils documentation for details. As rclpy and rclcpp both use rcutils for logging, this will effect all Python and C++ nodes. 

預設情況下,控制台輸出将被格式化為包括消息嚴重性,記錄器名稱和消息。還可以使用日志調用的檔案名,函數名和行号等資訊。可以使用RCUTILS_CONSOLE_OUTPUT_FORMAT環境變量配置自定義控制台輸出格式:有關詳細資訊,請參考rcutils文檔。由于rclpy和rclcpp都使用rcutils了日志記錄,這将影響所有的Python和C ++節點。

Features Status 功能狀态

The features listed below are available in the current ROS 2 release. Unless otherwise specified, the features are available for all supported platforms (Ubuntu 18.04, OS X 10.12.x, Windows 10), DDS implementations (eProsima Fast RTPS, RTI Connext and ADLINK Opensplice) and programming language client libraries (C++ and Python). For planned future development, see the Roadmap. 

下面列出的功能可在目前的ROS 2版本中找到。除非另有說明,否則這些功能适用于所有支援的平台(Ubuntu 18.04,OS X 10.12.x,Windows 10),DDS實作版本(eProsima Fast RTPS、RTI Connext和ADLINK Opensplice)和程式設計語言用戶端庫(C ++和Python)。有關未來發展的計劃,請參考路線圖。

Functionality 功能

Link 連結

Fine print

Discovery, transport and serialization over DDS 通過DDS進行發現,傳輸和序列化

Article

Support for multiple DDS implementations, chosen at runtime 

支援在運作時選擇的多個DDS實作

Tutorials

Currently eProsima Fast RTPS, RTI Connext and ADLINK OpenSplice are fully supported.

Common core client library that is wrapped by language-specific libraries 

由特定語言的庫封裝的公共核心用戶端庫

Details

Publish/subscribe over topics 

釋出/訂閱主題

Sample code, Article

Clients and services 

用戶端和服務端

Sample code

Set/retrieve parameters 

設定/檢索參數

ROS 1 - ROS 2 communication bridge 

ROS 1 - ROS 2通信橋接

Tutorial

Available for topics and services, not yet available for actions.

Quality of service settings for handling non-ideal networks 

處理非理想網絡的服務品質設定

Demo

Inter- and intra-process communication using the same API 

使用相同API的程序間和程序内通信

Currently only in C++.

Composition of node components at compile-, link- or dlopen-time 

編譯、連結或dlopen時間節點元件的組成

Support for nodes with managed lifecycles 

支援具有托管生命周期的節點

DDS-Security support 

DDS-Security支援

Command-line introspection tools using an extensible framework 

使用可擴充架構的指令行自檢工具

Launch system for coordinating multiple nodes 

啟動系統以協調多個節點

Namespace support for nodes and topics 

命名空間支援節點和主題

Static remapping of ROS names 

靜态重新映射ROS名稱

Demos of an all-ROS 2 mobile robot 

全ROS 2移動機器人的示範

Preliminary support for real-time code 

初步支援實時代碼

Demo, demo

Linux only. Not available for Fast RTPS.

Preliminary support for “bare-metal” microcontrollers 

對“bare-meta”微控制器的初步支援

Wiki

Beside features of the platform the most impact of ROS comes from its available packages. The following are a few high profile packages which are available in the latest release: 

除了平台的功能外,ROS的最大影響來自其可用的包。以下是最新版本中提供的一些進階别功能的軟體包:

gazebo_ros_pkgs

image_transport

navigation2

rosbag2

RQt

RViz2