diff --git a/README.md b/README.md index c64bb2a..bd4d14c 100644 --- a/README.md +++ b/README.md @@ -34,32 +34,23 @@ cargo add logforth Then, you can use the logger with the simplest default setup: ```rust -use log::LevelFilter; -use logforth::append; -use logforth::layout::TextLayout; -use logforth::Dispatch; -use logforth::Logger; - fn main() { - Logger::new().dispatch( - Dispatch::new() - .filter(LevelFilter::Trace) - .append(append::Stdout::default()), - ) - .apply() - .unwrap(); - - log::error!("Hello error!"); - log::warn!("Hello warn!"); - log::info!("Hello info!"); - log::debug!("Hello debug!"); - log::trace!("Hello trace!"); + logforth::stderr().finish(); } ``` Or configure the logger in a more fine-grained way: ```rust +fn main() { + logforth::builder() + .filter(log::LevelFilter::Debug) + .append(logforth::append::Stderr::default()) + .dispatch() + .filter(log::LevelFilter::Info) + .append(logforth::append::Stdout::default()) + .finish(); +} ``` Read more demos under the [examples](examples) directory. diff --git a/examples/env_filter.rs b/examples/env_filter.rs index dc8ec57..e423481 100644 --- a/examples/env_filter.rs +++ b/examples/env_filter.rs @@ -19,8 +19,7 @@ fn main() { logforth::builder() .filter(EnvFilter::from_default_env()) .append(append::Stdout::default()) - .finish() - .unwrap(); + .finish(); log::error!("Hello error!"); log::warn!("Hello warn!"); diff --git a/examples/fn_layout_filter.rs b/examples/fn_layout_filter.rs index deedefc..eae0c34 100644 --- a/examples/fn_layout_filter.rs +++ b/examples/fn_layout_filter.rs @@ -32,8 +32,8 @@ fn main() { Ok(format!("[system alert] {}", record.args()).into_bytes()) })), ) - .finish() - .unwrap(); + .finish(); + log::error!("Hello error!"); log::warn!("Hello warn!"); log::info!("Hello info!"); diff --git a/examples/json_stdio.rs b/examples/json_stdio.rs index bcf1777..c6e0760 100644 --- a/examples/json_stdio.rs +++ b/examples/json_stdio.rs @@ -18,8 +18,7 @@ use logforth::layout::JsonLayout; fn main() { logforth::builder() .append(append::Stdout::default().with_layout(JsonLayout::default())) - .finish() - .unwrap(); + .finish(); log::error!("Hello error!"); log::warn!("Hello warn!"); diff --git a/examples/rolling_file.rs b/examples/rolling_file.rs index 6cb4775..1b60424 100644 --- a/examples/rolling_file.rs +++ b/examples/rolling_file.rs @@ -36,8 +36,7 @@ fn main() { .dispatch() .filter("info") .append(Stdout::default()) - .finish() - .unwrap(); + .finish(); let repeat = 1; diff --git a/examples/simple_stdio.rs b/examples/simple_stdio.rs index cb3e3c5..992fa9e 100644 --- a/examples/simple_stdio.rs +++ b/examples/simple_stdio.rs @@ -20,8 +20,7 @@ fn main() { .filter(LevelFilter::Trace) .append(append::Stdout::default()) .append(append::Stderr::default()) - .finish() - .unwrap(); + .finish(); log::error!("Hello error!"); log::warn!("Hello warn!"); diff --git a/src/lib.rs b/src/lib.rs index e691342..8c2e1fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,39 +12,40 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! # A versatile and extensible logging implementation -//! -//! ## Usage -//! -//! Add the dependencies to your `Cargo.toml` with: -//! -//! ```shell -//! cargo add log -//! cargo add logforth -//! ``` -//! -//! Here, [`log`] is the logging facade and `logforth` is the logging implementation. -//! -//! Then, you can use the logger with: -//! -//! ```rust -//! use log::LevelFilter; -//! use logforth::append; -//! -//! logforth::builder() -//! .filter(LevelFilter::Info) -//! .append(append::Stdout::default()) -//! .finish() -//! .unwrap(); -//! -//! log::error!("Hello error!"); -//! log::warn!("Hello warn!"); -//! log::info!("Hello info!"); -//! log::debug!("Hello debug!"); -//! log::trace!("Hello trace!"); -//! ``` -//! -//! Read more demos under the [examples](https://github.com/fast/logforth/tree/main/examples) directory. +/*! +# A versatile and extensible logging implementation + +## Usage + +Add the dependencies to your `Cargo.toml` with: + +```shell +cargo add log +cargo add logforth +``` + +[`log`] is the logging facade and `logforth` is the logging implementation. + +Then, you can use the logger with the simplest default setup: + +```rust +logforth::stderr().finish(); +``` + +Or configure the logger in a more fine-grained way: + +```rust +logforth::builder() + .filter(log::LevelFilter::Debug) + .append(logforth::append::Stderr::default()) + .dispatch() + .filter(log::LevelFilter::Info) + .append(logforth::append::Stdout::default()) + .finish(); +``` + +Read more demos under the [examples](https://github.com/fast/logforth/tree/main/examples) directory. +*/ #![cfg_attr(docsrs, feature(doc_auto_cfg))] diff --git a/tests/recursive_logging.rs b/tests/recursive_logging.rs index ebd952d..f9bc2a3 100644 --- a/tests/recursive_logging.rs +++ b/tests/recursive_logging.rs @@ -43,8 +43,7 @@ fn test_meta_logging_in_format_works() { .append(append::Stderr::default().with_layout(layout("err"))) .dispatch() .append(append::RollingFile::new(writer).with_layout(layout("file"))) - .finish() - .unwrap(); + .finish(); struct Thing<'a>(&'a str);