Git Product home page Git Product logo

simple-log's Introduction

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]
simple-log = "1.5.1"
#[macro_use]
extern crate simple_log;

fn main() {
    simple_log::quick!("info"); // also use empty args: simple_log::quick!();
    // simple_log::quick!(); //use debug log_level
    
    debug!("test quick debug");
    info!("test quick info");
}

Usage in project

[dependencies]
simple-log = "1.5.1"
#[macro_use]
extern crate simple_log;

use simple_log::LogConfigBuilder;

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

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

Config with toml

[dependencies]
simple-log = "1.5.1"
toml = "0.5.7"
#[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#"
    [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
    time_format = "%H:%M:%S.%f"
    "#;
    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]
simple-log = "1.5.1"
serde_json = "1"
#[macro_use]
extern crate simple_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,
        "time_format":"%H:%M:%S.%f"
    }"#;
    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.

simple-log's People

Contributors

baoyachi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

isgasho 00mjk zidaye

simple-log's Issues

extern crate simple_log make used macro

like this:

#[macro_use(quick)]
extren crate simple_log;

#[macro_use]
extern crate log;

fn main() -> Result<(), String> {
    debug!("test builder debug");
    info!("test builder info");
    Ok(())
}

newline ending

Hello. Does it possible for logger macroc (info! error! etc) to be aware of plaform with newline? On linux all is fine, but when run on windows it seems newline is only \n, without \r. May be i can configure it somehow ?

add color support

mabe add .color() in config builder, and add the color in default feature so that it can be used in no_std env.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.