-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pretty logging with
FmtSubscriber
(#2)
* Add pretty fmt logger * Change import name in README.md * Add docs * Deny missing docs in lib
- Loading branch information
Showing
8 changed files
with
263 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use lunatic_log::{debug, error, info, subscriber::fmt::FmtSubscriber, trace, warn, LevelFilter}; | ||
|
||
fn main() { | ||
// Initialize subscriber | ||
lunatic_log::init(FmtSubscriber::new(LevelFilter::Trace).pretty()); | ||
|
||
// Log message | ||
error!("Error"); | ||
warn!("Warn"); | ||
info!("Info"); | ||
debug!("Debug"); | ||
trace!("Trace"); | ||
|
||
// Wait for events to propagate | ||
lunatic::sleep(std::time::Duration::from_millis(50)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,39 @@ | ||
//! A [`Subscriber`] handles log events. | ||
//! | ||
//! It can be used to print to stdout with [`FmtSubscriber`](fmt::FmtSubscriber), | ||
//! but is also capable of handling logs in other ways. | ||
pub mod fmt; | ||
pub mod multiple; | ||
|
||
use serde::{de::DeserializeOwned, Serialize}; | ||
|
||
use crate::{Event, Metadata}; | ||
|
||
/// A subscriber which handles incoming log [`Event`]s. | ||
/// | ||
/// # Example | ||
/// | ||
/// ``` | ||
/// #[derive(Serialize, Deserialize)] | ||
/// pub struct FmtSubscriber { | ||
/// level_filter: LevelFilter, | ||
/// } | ||
/// | ||
/// impl Subscriber for FmtSubscriber { | ||
/// fn enabled(&self, metadata: &Metadata) -> bool { | ||
/// metadata.level() <= &self.level_filter | ||
/// } | ||
/// | ||
/// fn event(&self, event: &Event) { | ||
/// println!("Log: {}", event.message()); | ||
/// } | ||
/// } | ||
/// ``` | ||
pub trait Subscriber: Serialize + DeserializeOwned { | ||
/// Indicate whether subscriber is enabled given some [`Metadata`]. | ||
fn enabled(&self, metadata: &Metadata) -> bool; | ||
|
||
/// Handle a log [`Event`]. | ||
fn event(&self, event: &Event); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters