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§
Sourceconst FALLBACK_TARGET: &'static str
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
12345is the timestamp/block numberINFOis the log levelpallet_templateis 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§
Sourcetype Logger: Elastic + RuntimeEnum
type Logger: Elastic + RuntimeEnum
The error/logging type propagated through the API.
Logging responsibility is directional:
- If a
Loggeris returned from the provider (i.e., received by the caller), it has already been logged. - If a
Loggeris constructed by the caller and returned to the provider, it is expected that the provider will perform the logging.
Sourcetype Level: RuntimeEnum + From<&'static str>
type Level: RuntimeEnum + From<&'static str>
The log level type (Info/Warn/Error/Debug)
Required Methods§
Sourcefn log(
level: Self::Level,
err: &Self::Logger,
timestamp: Timestamp,
target: Option<&str>,
fmt: Option<LogFormatter<Timestamp, Self::Level>>,
) -> Self::Logger
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§
Sourcefn info(
err: &Self::Logger,
timestamp: Timestamp,
target: Option<&str>,
fmt: Option<LogFormatter<Timestamp, Self::Level>>,
) -> Self::Loggerwhere
Self: Sized,
fn info(
err: &Self::Logger,
timestamp: Timestamp,
target: Option<&str>,
fmt: Option<LogFormatter<Timestamp, Self::Level>>,
) -> Self::Loggerwhere
Self: Sized,
Logs an info-level message.
Includes an optional custom formatter and log target.
Sourcefn warn(
err: &Self::Logger,
timestamp: Timestamp,
target: Option<&str>,
fmt: Option<LogFormatter<Timestamp, Self::Level>>,
) -> Self::Loggerwhere
Self: Sized,
fn warn(
err: &Self::Logger,
timestamp: Timestamp,
target: Option<&str>,
fmt: Option<LogFormatter<Timestamp, Self::Level>>,
) -> Self::Loggerwhere
Self: Sized,
Logs a warning-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.