pub trait MessageFormatter:
Send
+ Sync
+ Default {
// Required methods
fn format_io(
&mut self,
message: &Message,
write: &mut (dyn Write + Send + Sync),
) -> Result<(), ServiceError>;
fn format_fmt(
&mut self,
message: &Message,
write: &mut (dyn Write + Send + Sync),
) -> Result<(), ServiceError>;
}Expand description
Trait defining the behavior for formatting log messages.
Implementations are responsible for defining the layout (timestamp, level, content) and writing the result to an I/O sink.
Required Methods§
Sourcefn format_io(
&mut self,
message: &Message,
write: &mut (dyn Write + Send + Sync),
) -> Result<(), ServiceError>
fn format_io( &mut self, message: &Message, write: &mut (dyn Write + Send + Sync), ) -> Result<(), ServiceError>
Formats and writes the message to the provided I/O sink.
§Implementation Requirements
- Atomicity: To ensure log integrity in concurrent environments, implementations
should minimize the number of calls to the writer. Using a single
write!macro or a buffered approach is highly recommended. - Thread Safety: The
writeris guaranteed to beSend + Sync. However, some global sinks (likestd::io::stdout()) may not support explicit locking while maintaining these bounds.
§Errors
Returns ServiceError if formatting fails or the writer encounters an I/O error.
Sourcefn format_fmt(
&mut self,
message: &Message,
write: &mut (dyn Write + Send + Sync),
) -> Result<(), ServiceError>
fn format_fmt( &mut self, message: &Message, write: &mut (dyn Write + Send + Sync), ) -> Result<(), ServiceError>
Formats a message specifically for fmt-based destinations.
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§
impl MessageFormatter for CloudWatchCoutMessageFormatter
Available on crate feature
awscout only.