holochain_integrity_types/trace.rs
1//! Types related to the `debug` host function
2
3use holochain_serialized_bytes::prelude::*;
4
5/// Maps directly to the tracing Levels but here to define the interface.
6/// See <https://docs.rs/tracing-core/0.1.17/tracing_core/struct.Level.html>
7#[derive(PartialEq, Eq, serde::Serialize, serde::Deserialize, Debug, Clone)]
8#[allow(clippy::upper_case_acronyms)]
9pub enum Level {
10 /// Error.
11 ERROR,
12 /// Warning.
13 WARN,
14 /// Info.
15 INFO,
16 /// Debug.
17 DEBUG,
18 /// Trace.
19 TRACE,
20}
21
22#[cfg(feature = "tracing")]
23impl From<&tracing::Level> for Level {
24 fn from(level: &tracing::Level) -> Self {
25 match *level {
26 tracing::Level::ERROR => Self::ERROR,
27 tracing::Level::WARN => Self::WARN,
28 tracing::Level::INFO => Self::INFO,
29 tracing::Level::DEBUG => Self::DEBUG,
30 tracing::Level::TRACE => Self::TRACE,
31 }
32 }
33}
34
35/// Representation of message to be logged via the `debug` host function
36#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
37pub struct TraceMsg {
38 /// A formatted string to be forwarded to `tracing` on the host side.
39 ///
40 /// The host will provide:
41 /// - Timestamps
42 /// - ANSI coloured levels
43 ///
44 /// The guest should provide:
45 /// - Useful message
46 /// - Line numbers etc.
47 pub msg: String,
48 /// Severity level for the message.
49 pub level: Level,
50}