28 stable releases

2.1.1 Oct 8, 2024
1.9.0 Sep 14, 2024
1.6.0 Jul 19, 2022
1.5.1 Feb 24, 2022
0.1.0 Nov 30, 2020

#105 in Debugging

Download history 518/week @ 2024-08-23 473/week @ 2024-08-30 560/week @ 2024-09-06 682/week @ 2024-09-13 771/week @ 2024-09-20 623/week @ 2024-09-27 699/week @ 2024-10-04 610/week @ 2024-10-11 305/week @ 2024-10-18 214/week @ 2024-10-25 288/week @ 2024-11-01 135/week @ 2024-11-08 441/week @ 2024-11-15 300/week @ 2024-11-22 377/week @ 2024-11-29 308/week @ 2024-12-06

1,451 downloads per month
Used in 18 crates

MIT/Apache

40KB
644 lines

simple-log

A simple-log with local file or stdout write by Rust.

Crates.io Crates.io depstatus Crates.io

simple-log format output

2020-12-07 15:06:03.260570000 [INFO] <json_log:16>:info json simple_log
2020-12-07 15:06:03.262106000 [WARN] <json_log:17>:warn json simple_log
2020-12-07 15:06:03.262174000 [ERROR] <json_log:18>:error json simple_log

Quick Use

[dependencies]
simple-log = "{latest}"
#[macro_use]
extern crate simple_log;

fn main() {
    simple_log::quick!("info"); // also use empty args: simple_log::quick!();
    // simple_log::quick!(); //use debug log_level
    
    debug!("test quick debug");
    info!("test quick info");
}

Usage in project

[dependencies]
simple-log = "{latest}"
#[macro_use]
extern crate simple_log;

use simple_log::LogConfigBuilder;

fn main() -> Result<(), String> {
    let config = LogConfigBuilder::builder()
        .path("./log/builder_log.log")
        .size(1 * 100)
        .roll_count(10)
        .time_format("%Y-%m-%d %H:%M:%S.%f") //E.g:%H:%M:%S.%f
        .level("debug")?
        .output_file()
        .output_console()
        .build();

    simple_log::new(config)?;
    debug!("test builder debug");
    info!("test builder info");
    Ok(())
}

Config with toml

[dependencies]
simple-log = "{latest}"
toml = "0.5.7"
#[macro_use]
extern crate simple_log;

#[macro_use]
extern crate serde_derive;

use simple_log::LogConfig;

#[derive(Deserialize)]
struct LogConfigWrap {
    log_config: LogConfig,
}

fn main() {
    let config = r#"
    [log_config]
    path = "./log/tmp.log"
    level = "debug"
    size = 10
    out_kind = ["console","file"] # also configure only with file: out_kind = "file"  
    roll_count = 10
    time_format = "%H:%M:%S.%f"
    "#;
    let wrap: LogConfigWrap = toml::from_str(config).unwrap();

    simple_log::new(wrap.log_config).unwrap();//init log

    info!("info toml simple_log");
    warn!("warn toml simple_log");
    error!("error toml simple_log");
}

Config with json

[dependencies]
simple-log = "{latest}"
serde_json = "1"
#[macro_use]
extern crate simple_log;

use simple_log::LogConfig;

fn main() {
    let config = r#"
    {
        "path":"./log/tmp.log",
        "level":"debug",
        "size":10,
        "out_kind":["console","file"],
        "roll_count":10,
        "time_format":"%H:%M:%S.%f"
    }"#;
    let log_config: LogConfig = serde_json::from_str(config).unwrap();

    simple_log::new(log_config).unwrap();//init log

    info!("info json simple_log");
    warn!("warn json simple_log");
    error!("error json simple_log");
}

examples

More than examples can see examples.

Dependencies

~1.2–2.4MB
~49K SLoC