3 unstable releases

0.2.0 Jun 29, 2021
0.1.1 Jun 28, 2021
0.1.0 Jun 28, 2021

#807 in Debugging

MPL-2.0 license

10KB
120 lines

basic_log

crates.io License badge Latest commit

A basic logging crate for Rust.


Focuses on having sensible defaults for basic logging to accomplish great out of the box functionality.

Usage

To use the default settings, simply create and initialise the logger
The crate exposes the logging macros provided by log for easy access

use basic_log::{BasicLog, info, warn, error};

fn main() {
  BasicLog::new()
    .init()
    .expect("Failed to initialise BasicLog");

  info!("Example info message");
  warn!("Example warning");
  error!("Example error");
}

To change logger behaviour you can use a closure or a settings struct

use basic_log::{BasicLog, trace, debug};

fn main() {
  BasicLog::new_with_settings(
    |s| 
      s
      .enable_debug()
      .enable_trace()
    )
    .init()
    .expect("Failed to initialise BasicLog");

  trace!("Example trace message");
  debug!("Example debug message");
}
use basic_log::{BasicLog, LoggerSettings, trace, debug};

fn main() {
  let log_settings = LoggerSettings::new()
    .enable_debug()
    .enable_trace();

  BasicLog::new_with_struct(log_settings)
    .init()
    .expect("Failed to initialise BasicLog");

  trace!("Example trace message");
  debug!("Example debug message");
}

Dependencies

~1–11MB
~62K SLoC