#log #logging #simplelog #filelog

simplelog

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

14 releases

0.5.3 Oct 10, 2018
0.5.2 May 13, 2018
0.5.1 Mar 22, 2018
0.4.4 Dec 11, 2017
0.1.0 Mar 31, 2016

#6 in Debugging

Download history 3481/week @ 2018-10-11 4774/week @ 2018-10-18 4461/week @ 2018-10-25 4755/week @ 2018-11-01 5203/week @ 2018-11-08 6150/week @ 2018-11-15 5498/week @ 2018-11-22 5047/week @ 2018-11-29 7125/week @ 2018-12-06 6770/week @ 2018-12-13 6348/week @ 2018-12-20 4442/week @ 2018-12-27 2480/week @ 2019-01-03

22,425 downloads per month
Used in 52 crates (45 directly)

MIT/Apache

33KB
512 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()).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.5.0 (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.5.0"

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

~1.5MB
~16K SLoC