sloggers/lib.rs
1//! This crate provides frequently used
2//! [slog](https://github.com/slog-rs/slog) loggers and convenient functions.
3//!
4//! **Important note:** this crate is optimized for performance rather than for
5//! not losing any messages! This may be surprising in some common scenarios,
6//! like logging an error message and calling `std::process::exit(1)`. It's
7//! recommended to drop the logger(s) before exiting. `panic = "abort"` may have
8//! the same surprising effect, so unwinding is preferrable if you want to avoid
9//! losing the messages. See [#29](https://github.com/sile/sloggers/issues/29) for
10//! more information.
11//!
12//! # Examples
13//!
14//! Creates a logger via `TerminalLoggerBuilder`:
15//!
16//! ```
17//! use slog::info;
18//! use sloggers::Build;
19//! use sloggers::terminal::{TerminalLoggerBuilder, Destination};
20//! use sloggers::types::Severity;
21//!
22//! let mut builder = TerminalLoggerBuilder::new();
23//! builder.level(Severity::Debug);
24//! builder.destination(Destination::Stderr);
25//!
26//! let logger = builder.build().unwrap();
27//! info!(logger, "Hello World!");
28//! ```
29//!
30//! Creates a logger from configuration text (TOML):
31//!
32//! ```
33//! use slog::info;
34//! use sloggers::{Config, LoggerConfig};
35//!
36//! let config: LoggerConfig = serdeconv::from_toml_str(r#"
37//! type = "terminal"
38//! level = "debug"
39//! destination = "stderr"
40//! "#).unwrap();
41//!
42//! let logger = config.build_logger().unwrap();
43//! info!(logger, "Hello World!");
44//! ```
45#![warn(missing_docs)]
46#[macro_use]
47extern crate slog;
48#[macro_use]
49extern crate trackable;
50
51pub use build::{Build, BuildWithCustomFormat, LoggerBuilder};
52pub use config::{Config, LoggerConfig};
53pub use error::{Error, ErrorKind};
54pub use misc::set_stdlog_logger;
55
56pub mod file;
57pub mod null;
58pub mod syslog;
59pub mod terminal;
60pub mod types;
61
62mod build;
63mod config;
64mod error;
65mod fake_syslog;
66mod misc;
67mod permissions;
68
69/// A specialized `Result` type for this crate.
70pub type Result<T> = ::std::result::Result<T, Error>;