basic_log

Crates.iobasic_log
lib.rsbasic_log
version0.2.0
sourcesrc
created_at2021-06-28 21:00:01.460642
updated_at2021-06-29 21:14:03.928634
descriptionA basic logging crate for Rust.
homepagehttps://github.com/mxrr/basic_log
repositoryhttps://github.com/mxrr/basic_log
max_upload_size
id415909
size28,234
mxr (mxrr)

documentation

README

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");
}
Commit count: 22

cargo fmt