Crate simple_log[][src]

Expand description

simple-log is a very simple configuration log crates.

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 Start

To get you started quickly, the easiest and quick way to used with demo or test project

#[macro_use]
extern crate log;

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

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

Usage in project

Configuration LogConfig in your project.

#[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 json

#[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");
}

For the user guide and futher documentation, please read The simple-log document.

More than examples can see: examples.

Modules

log_level

Structs

LogConfig
LogConfigBuilder

The LogConfig with builder wrapper.

Functions

console

Provide init simple-log instance with stdout console on terminal.

file

Provide init simple-log instance with write file.

get_log_conf

Get simple-log global config LogConfig

new

The new method provide init simple-log instance with config.

quick

This method can quick init simple-log with no configuration.

update_log_conf

Update simple-log global config LogConfig.

update_log_level

update simple-log global config log level.