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] log = "0.4" simple-log = "1.0.0"

```rust

[macro_use]

extern crate log;

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

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

} ```

Usage in project

toml [dependencies] log = "0.4" simple-log = "1.0.0" ```rust

[macro_use]

extern crate log;

use simple_log::LogConfigBuilder;

fn main() -> Result<(), String> { let config = LogConfigBuilder::builder() .path("./log/builderlog.log") .size(1 * 100) .rollcount(10) .level("debug") .outputfile() .outputconsole() .build();

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

} ```

Config with json

toml [dependencies] log = "0.4" simple-log = "1.0.0" serde_json = "1"

```rust

[macro_use]

extern crate log;

use simple_log::LogConfig;

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

} ```

Config with toml

toml [dependencies] log = "0.4" simple-log = "1.0.0" toml = "0.5.7"

```rust

[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#" [logconfig] path = "./log/tmp.log" level = "debug" size = 10 outkind = ["console","file"] rollcount = 10 "#; 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");

} ```

examples

More than examples can see examples.