logs

Crates.iologs
lib.rslogs
version0.7.1
sourcesrc
created_at2020-07-06 09:02:41.98971
updated_at2022-11-10 09:36:34.439676
descriptionA simple terminal logger
homepagehttps://github.com/wyhaya/logs
repositoryhttps://github.com/wyhaya/logs.git
max_upload_size
id261889
size10,726
(wyhaya)

documentation

README

logs

Crates.io docs.rs Crates.io

A simple terminal logger

Usage

Add this in your Cargo.toml:

[dependencies]
logs = "*"

Example

use logs::{debug, error, info, trace, warn, Logs};

fn main() {
    Logs::new().init();

    trace!("This is a trace log");
    debug!("This is a debug log");
    info!("This is a info log");
    warn!("This is a warn log");
    error!("This is a error log");
}

Output:

2022-09-06T08:38:23.490 [TRACE] This is a trace log
2022-09-06T08:38:23.490 [DEBUG] This is a debug log
2022-09-06T08:38:23.490 [INFO ] This is a info log
2022-09-06T08:38:23.490 [WARN ] This is a warn log
2022-09-06T08:38:23.490 [ERROR] This is a error log

Options

use logs::{Logs, debug, error, LevelFilter};

fn main() {
    Logs::new()
        // Show log level color
        .color(true)
        // Filter log target
        .target("target")
        // Filter log level
        .level(LevelFilter::Info)
        // Filter log target from `LOG` environment variable
        .level_from_default_env()
        .unwrap()
        // Filter log target from `NAME` environment variable
        .level_from_env("NAME")
        .unwrap()
        // Filter log level from str
        .level_from_str("info")
        .unwrap()
        // Apply
        .init();
}

Commit count: 5

cargo fmt