11 releases (7 stable)

1.0.6 May 18, 2021
1.0.5 May 17, 2021
1.0.2 Apr 22, 2021
1.0.1 Dec 12, 2020
0.1.0 Nov 30, 2020

#92 in Debugging

Download history 26/week @ 2021-04-10 59/week @ 2021-04-17 24/week @ 2021-04-24 28/week @ 2021-05-01 21/week @ 2021-05-08 92/week @ 2021-05-15 18/week @ 2021-05-22 33/week @ 2021-05-29 28/week @ 2021-06-05 44/week @ 2021-06-12 35/week @ 2021-06-19 35/week @ 2021-06-26 30/week @ 2021-07-03 34/week @ 2021-07-10 31/week @ 2021-07-17 33/week @ 2021-07-24

145 downloads per month
Used in 3 crates

MIT AND Apache-2.0

25KB
302 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]
log = "0.4"
simple-log = "1.0.0"
#[macro_use]
extern crate log;

fn main() -> Result<(), String> {
    simple_log::quick()?;

    debug!("test quick debug");
    info!("test quick info");
    Ok(())
}

Usage in project

[dependencies]
log = "0.4"
simple-log = "1.0.0"
#[macro_use]
extern crate log;

use simple_log::LogConfigBuilder;

fn main() -> Result<(), String> {
    let config = LogConfigBuilder::builder()
        .path("./log/builder_log.log")
        .size(1 * 100)
        .roll_count(10)
        .level("debug")
        .output_file()
        .output_console()
        .build();

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

Config with toml

[dependencies]
log = "0.4"
simple-log = "1.0.0"
toml = "0.5.7"
#[macro_use]
extern crate 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
    "#;
    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]
log = "0.4"
simple-log = "1.0.0"
serde_json = "1"
#[macro_use]
extern crate 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
    }"#;
    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–1.8MB
~40K SLoC