ros2_client/
log.rs

1//! `rosout` logging data types
2
3use serde::{Deserialize, Serialize};
4use rustdds::*;
5
6/// Log message structure, communicated over the rosout Topic.
7///
8/// [Log](https://github.com/ros2/rcl_interfaces/blob/master/rcl_interfaces/msg/Log.msg)
9///
10/// To write log messages, use the [`rosout`](crate::rosout!) macro.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct Log {
13  pub timestamp: Timestamp,
14  pub level: u8,
15  pub name: String,
16  pub msg: String,
17  pub file: String,
18  pub function: String,
19  pub line: u32,
20}
21
22impl Log {
23  /// ROS2 logging severity level
24  pub const DEBUG: u8 = 10;
25  pub const INFO: u8 = 20;
26  pub const WARN: u8 = 30;
27  pub const ERROR: u8 = 40;
28  pub const FATAL: u8 = 50;
29
30  /// Timestamp when rosout message was sent
31  pub fn get_timestamp(&self) -> &Timestamp {
32    &self.timestamp
33  }
34
35  /// Rosout level
36  pub fn get_level(&self) -> u8 {
37    self.level
38  }
39
40  /// Name of the rosout message
41  pub fn name(&self) -> &str {
42    &self.name
43  }
44
45  /// Actual message
46  pub fn get_msg(&self) -> &str {
47    &self.msg
48  }
49
50  pub fn get_file(&self) -> &str {
51    &self.file
52  }
53
54  pub fn get_function(&self) -> &str {
55    &self.function
56  }
57
58  pub fn get_line(&self) -> u32 {
59    self.line
60  }
61}
62
63#[repr(u8)]
64#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
65pub enum LogLevel {
66  Fatal = 50,
67  Error = 40,
68  Warn = 30,
69  Info = 20,
70  Debug = 10,
71}
72
73//impl From<u8> for Level