Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added example to lib.rs #4

Merged
merged 1 commit into from
Feb 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
//! A logger implementation to use RTT with the Rust `log` crate.
//!
//! ```
//! use log::{info, LevelFilter};
//! use rtt_logger::RTTLogger;
//! use rtt_target::rtt_init_print;
//!
//! // logger configuration
//! const LOG_LEVEL: LevelFilter = LevelFilter::Info;
//! static LOGGER: RTTLogger = RTTLogger::new(LOG_LEVEL);
//!
//! fn main() {
//! // logger setup
//! rtt_init_print!();
//! log::set_logger(&LOGGER)
//! .map(|()| log::set_max_level(LOG_LEVEL))
//! .unwrap();
//!
//! // logger usage in main binary or in any library
//! info!("Hello World!");
//! }
//! ```

#![no_std]

use log::{Metadata, Record, LevelFilter};
use log::{LevelFilter, Metadata, Record};

use rtt_target::*;

Expand All @@ -14,9 +37,7 @@ impl RTTLogger {
///
/// * `level_filter`: The default level to enable.
pub const fn new(level_filter: LevelFilter) -> RTTLogger {
RTTLogger {
level_filter
}
RTTLogger { level_filter }
}
}

Expand All @@ -31,7 +52,5 @@ impl log::Log for RTTLogger {
}
}

fn flush(&self) {
}
fn flush(&self) {}
}