Trait Logging

Source
pub trait Logging<Timestamp>
where Timestamp: Time,
{ type Logger: Elastic + RuntimeEnum; type Level: RuntimeEnum + From<&'static str>; const FALLBACK_TARGET: &'static str; // Required method fn log( level: Self::Level, err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<LogFormatter<Timestamp, Self::Level>>, ) -> Self::Logger; // Provided methods fn info( err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<LogFormatter<Timestamp, Self::Level>>, ) -> Self::Logger where Self: Sized { ... } fn warn( err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<LogFormatter<Timestamp, Self::Level>>, ) -> Self::Logger where Self: Sized { ... } fn error( err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<LogFormatter<Timestamp, Self::Level>>, ) -> Self::Logger where Self: Sized { ... } fn debug( err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<LogFormatter<Timestamp, Self::Level>>, ) -> Self::Logger where Self: Sized { ... } }
Expand description

Trait for structured logging in detached, asynchronous routines.

This trait is intended for use in detached, asynchronous Routines or functions where errors are handled gracefully rather than propagated. The logging system records errors, warnings, info, or debug messages without affecting control flow.

§Type Parameters

  • Timestamp: The type used for timestamps in logs.

Required Associated Constants§

Source

const FALLBACK_TARGET: &'static str

Default log target if none is provided.

The log target is a label that identifies the source of a log message, typically a pallet, module, or subsystem. It helps to categorize and filter logs, making it easier to trace where messages come from in a complex runtime.

For example, in a log line like: [12345][INFO][pallet_template] Templating period has not started

  • 12345 is the timestamp/block number
  • INFO is the log level
  • pallet_template is the log target
  • The rest is the message

If the caller does not provide a target, the FALLBACK_TARGET constant is used as a default to ensure all logs have a meaningful source label.

Required Associated Types§

Source

type Logger: Elastic + RuntimeEnum

The error/logging type propagated through the API.

Logging responsibility is directional:

  • If a Logger is returned from the provider (i.e., received by the caller), it has already been logged.
  • If a Logger is constructed by the caller and returned to the provider, it is expected that the provider will perform the logging.
Source

type Level: RuntimeEnum + From<&'static str>

The log level type (Info/Warn/Error/Debug)

Required Methods§

Source

fn log( level: Self::Level, err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<LogFormatter<Timestamp, Self::Level>>, ) -> Self::Logger

Core logging function that all helpers delegate to.

This central function ensures consistent structure and formatting across all log messages.

The optional LogFormatter lets you override the default output style.

A formatter could add JSON structure, include node metadata, or embed contextual tags.

Provided Methods§

Source

fn info( err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<LogFormatter<Timestamp, Self::Level>>, ) -> Self::Logger
where Self: Sized,

Logs an info-level message.

Includes an optional custom formatter and log target.

Source

fn warn( err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<LogFormatter<Timestamp, Self::Level>>, ) -> Self::Logger
where Self: Sized,

Logs a warning-level message.

Includes an optional custom formatter and log target.

Source

fn error( err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<LogFormatter<Timestamp, Self::Level>>, ) -> Self::Logger
where Self: Sized,

Logs an error-level message.

Includes an optional custom formatter and log target.

Source

fn debug( err: &Self::Logger, timestamp: Timestamp, target: Option<&str>, fmt: Option<LogFormatter<Timestamp, Self::Level>>, ) -> Self::Logger
where Self: Sized,

Logs a debug-level message.

Includes an optional custom formatter and log target.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T, Time> Logging<Time> for T
where Time: Time,

Blanket implementation of Logging for any runtime-type.

Source§

const FALLBACK_TARGET: &str = "routine"

Source§

type Logger = DispatchError

Source§

type Level = LogLevel