#log #logging #simplelog #filelog

simplelog

A simple and easy-to-use logging facility for Rust’s log crate

20 releases

✓ Uses Rust 2018 edition

new 0.7.4 Oct 12, 2019
0.7.1 Aug 24, 2019
0.6.0 Jun 17, 2019
0.5.3 Oct 10, 2018
0.1.0 Mar 31, 2016

#5 in Debugging

Download history 3302/week @ 2019-06-03 3016/week @ 2019-06-10 3191/week @ 2019-06-17 3638/week @ 2019-06-24 3293/week @ 2019-07-01 3292/week @ 2019-07-08 3209/week @ 2019-07-15 2929/week @ 2019-07-22 3723/week @ 2019-07-29 4079/week @ 2019-08-05 3488/week @ 2019-08-12 3943/week @ 2019-08-19 3611/week @ 2019-08-26 4565/week @ 2019-09-02 4031/week @ 2019-09-09

17,732 downloads per month
Used in 83 crates (76 directly)

MIT/Apache

53KB
916 lines

simplelog Build Status Coverage Status Crates.io Crates.io

A simple and easy-to-use logging facility for Rust's log crate

simplelog does not aim to provide a rich set of features, nor to provide the best logging solution. It aims to be a maintainable, easy to integrate facility for small to medium sized projects, that find env_logger to be somewhat lacking in features. In those cases simplelog should provide an easy alternative.

Concept

simplelog provides a series of logging facilities, that can be easily combined.

  • SimpleLogger (very basic logger that logs to stderr/out, should never fail)
  • TermLogger (advanced terminal logger, that splits to stderr/out and has color support) (can be excluded on unsupported platforms)
  • WriteLogger (logs to a given struct implementing Write. e.g. a file)
  • CombinedLogger (can be used to form combinations of the above loggers)

Usage

#[macro_use] extern crate log;
extern crate simplelog;

use simplelog::*;

use std::fs::File;

fn main() {
    CombinedLogger::init(
        vec![
            TermLogger::new(LevelFilter::Warn, Config::default(), TerminalMode::Mixed).unwrap(),
            WriteLogger::new(LevelFilter::Info, Config::default(), File::create("my_rust_binary.log").unwrap()),
        ]
    ).unwrap();

    error!("Bright red error");
    info!("This only appears in the log file");
    debug!("This level is currently not enabled for any logger");
}

Results in

$ cargo run --example usage
   Compiling simplelog v0.7.3 (file:///home/drakulix/Projects/simplelog)
     Running `target/debug/examples/usage`
[ERROR] Bright red error

and my_rust_binary.log

11:13:03 [ERROR] usage: Bright red error
11:13:03 [ INFO] usage: This only appears in the log file

Getting Started

Just add

[dependencies]
simplelog = "^0.7.3"

to your Cargo.toml

Documentation

Contributing

If you wish to contribute your own logger to simplelog or advance/extend existing loggers, feel free to create a pull request. Just don't blindly assume, that your logger will be accepted. The rational about this library is, that it is simple to use. This mostly comes down to a small and easy API, but also includes things like the amount of added dependencies. If you feel unsure about your plans, feel free to create an issue to talk about your ideas.

Happy Coding!

Dependencies

~0.8–1.2MB
~18K SLoC