Closed rohitjoshi closed 9 months ago
sloggers
only supports the formats defined by slog_term::CompactFormat
and slog_term::FullFormat
.
To keep this crate simple, sloggers probably does not provide custom message format functionality.
If you need it (or any other elaborate features), it is recommended to use slog
directly.
Thanks. Any suggestions on how to override? I have been using slog with implementing log trait for a drain but missing some of the common capabilities of sloggers. E.g. log rotate, keep num of files, compression etc
I tried adding BuildWithCustomFormat
for this purpose (in custom-format
branch).
It can be used as follows:
#[macro_use]
extern crate slog;
extern crate sloggers;
use sloggers::BuildWithCustomFormat; // Added
use sloggers::terminal::{TerminalLoggerBuilder, Destination};
let mut builder = TerminalLoggerBuilder::new();
builder.destination(Destination::Stderr);
let logger = builder.build_with_custom_format(|decorator| {
let drain = ...; // Create your own drain that uses `decorator` (slog_term::Decorator).
Ok(drain)
})).unwrap();
info!(logger, "Hello World!");
Is it sufficient for you?
Thanks, I will give a try. Appreciate your help.
How do I format a record as
Timestamp|Level|Module:Line|Msg
e.g.2019-03-14T07:13:58.740|INFO|abc::network_server:97|Starting connection handler child loop