Skip to content

Latest commit

 

History

History
executable file
·
99 lines (69 loc) · 4.44 KB

Logger.md

File metadata and controls

executable file
·
99 lines (69 loc) · 4.44 KB

Logging

校验等级::star::star::star::star:

API

ROS2 ROS1
// 普通输出
RCLCPP_INFO(this->get_logger(), "Publishing: '%s'", message.data.c_str());
// 普通输出
ROS_INFO("Publishing: '%s'", message.data.c_str());
// 流输出
RCLCPP_ERROR_STREAM(rclcpp::get_logger("lanelet2_extension.visualization"), __FUNCTION__ << ": marker is null pointer!");
// 流输出
ROS_ERROR_STREAM(__FUNCTION__ << ": marker is null pointer!");
// 定时输出
RCLCPP_ERROR_THROTTLE(get_logger(), *get_clock(), 5000/*unit: ms*/, "behavior path output is empty! Stop publish."))
// 定时输出
ROS_DEBUG_THROTTLE(60/*unit: sec*/, "This message will print every 60 seconds");
// 条件输出
RCLCPP_DEBUG_EXPRESSION
// 条件输出
ROS_DEBUG_COND(x < 0, "Uh oh, x = %d, this is bad", x);

ROS_DEBUG_STREAM_COND(x < 0, "Uh oh, x = " << x << ", this is bad");
// 跳过第一次的输出
RCLCPP_INFO_SKIPFIRST_THROTTLE(get_logger(), *get_clock(), 5000, "waiting for %s", name);
TODO
// 全局日志:
RCLCPP_ERROR(rclcpp::get_logger("data_process"), "clear lidar buffer, only happen at the beginning");
TODO

Usage

🔧 用例 1: ROS2 中使能含颜色的日志输出
$ export RCUTILS_COLORIZED_OUTPUT=1
🔧 用例 2: 指定某个节点的日志输出等级

ROS2

方案 1:ros2 run

# 指定某个节点的输出等级(DEBUG, INFO, WARN, ERROR or FATAL)
(ROS2) $ ros2 run <pkg> <executable> --ros-args --log-level <log-level>

ROS1

方案 1:修改程序

// 程序上的修改
#include <ros/console.h>

if(ros::console::set_logger_level(ROSCONSOLE_DEFAULT_NAME, ros::console::levels::Debug) ) {
   ros::console::notifyLoggerLevelsChanged();
}

方案 2:rqt_console
方案 3:配置文档

🔧 用例 3: RViz2 中如何使用日志功能
#include "rviz_common/logging.hpp"

// 不会输出到 /rosout
RVIZ_COMMON_LOG_INFO("Hello, world!");
RVIZ_COMMON_LOG_INFO_STREAM("Hello" << "world!");

// 会发布到 /rosout
// 其中的节点为 rviz 而非 rviz2
RCLCPP_INFO(rclcpp::get_logger("rviz"), "clicked: (%d, %d)", event.x, event.y);

Tools

rqt_console

  • 显示 ROS 的日志信息
$ rosrun rqt_console rqt_console

Reference

概要 ROS2 ROS1
官方文档 https://docs.ros.org/en/humble/Concepts/About-Logging.html http://wiki.ros.org/roscpp/Overview/Logging
API https://docs.ros2.org/bouncy/api/rclcpp/logging_8hpp.html http://wiki.ros.org/rosconsole