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

toml [dependencies] simple-log = "1.5.1"

```rust

[macro_use]

extern crate simple_log;

fn main() { simplelog::quick!("info"); // also use empty args: simplelog::quick!(); // simplelog::quick!(); //use debug loglevel

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

} ```

Usage in project

toml [dependencies] simple-log = "1.5.1" ```rust

[macro_use]

extern crate simple_log;

use simple_log::LogConfigBuilder;

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

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

} ```

Config with toml

toml [dependencies] simple-log = "1.5.1" toml = "0.5.7"

```rust

[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#" [logconfig] path = "./log/tmp.log" level = "debug" size = 10 outkind = ["console","file"] # also configure only with file: outkind = "file"
roll
count = 10 timeformat = "%H:%M:%S.%f" "#; let wrap: LogConfigWrap = toml::fromstr(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

toml [dependencies] simple-log = "1.5.1" serde_json = "1"

```rust

[macro_use]

extern crate simple_log;

use simple_log::LogConfig;

fn main() { let config = r#" { "path":"./log/tmp.log", "level":"debug", "size":10, "outkind":["console","file"], "rollcount":10, "timeformat":"%H:%M:%S.%f" }"#; let logconfig: LogConfig = serdejson::fromstr(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.