Expand description
This crate provides frequently used slog loggers and convenient functions.
Important note: this crate is optimized for performance rather than for
not losing any messages! This may be surprising in some common scenarios,
like logging an error message and calling std::process::exit(1)
. It’s
recommended to drop the logger(s) before exiting. panic = "abort"
may have
the same surprising effect, so unwinding is preferrable if you want to avoid
losing the messages. See #29 for
more information.
§Examples
Creates a logger via TerminalLoggerBuilder
:
use slog::info;
use sloggers::Build;
use sloggers::terminal::{TerminalLoggerBuilder, Destination};
use sloggers::types::Severity;
let mut builder = TerminalLoggerBuilder::new();
builder.level(Severity::Debug);
builder.destination(Destination::Stderr);
let logger = builder.build().unwrap();
info!(logger, "Hello World!");
Creates a logger from configuration text (TOML):
use slog::info;
use sloggers::{Config, LoggerConfig};
let config: LoggerConfig = serdeconv::from_toml_str(r#"
type = "terminal"
level = "debug"
destination = "stderr"
"#).unwrap();
let logger = config.build_logger().unwrap();
info!(logger, "Hello World!");
Modules§
Structs§
- Error
- The error type for this crate.
Enums§
- Error
Kind - A list of error kinds.
- Logger
Builder - Logger builder.
- Logger
Config - The configuration of
LoggerBuilder
.
Traits§
- Build
- This trait allows to build a logger instance.
- Build
With Custom Format - This trait allows to build a logger instance with a custom format (i.e.,
Drain
}. - Config
- Configuration of a logger builder.
Functions§
- set_
stdlog_ logger - Sets the logger for the log records emitted via
log
crate.
Type Aliases§
- Result
- A specialized
Result
type for this crate.