A simple-log with local file or stdout write by Rust.
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
toml
[dependencies]
log = "0.4"
simple-log = "1.0.0"
```rust
extern crate log;
fn main() -> Result<(), String> { simple_log::quick()?;
debug!("test quick debug");
info!("test quick info");
Ok(())
} ```
toml
[dependencies]
log = "0.4"
simple-log = "1.0.0"
```rust
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(())
} ```
toml
[dependencies]
log = "0.4"
simple-log = "1.0.0"
serde_json = "1"
```rust
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");
} ```
toml
[dependencies]
log = "0.4"
simple-log = "1.0.0"
toml = "0.5.7"
```rust
extern crate log;
extern crate serde_derive;
use simple_log::LogConfig;
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"
rollcount = 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");
} ```
More than examples can see examples.