Giter Club home page Giter Club logo

simplelog.rs's Introduction

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, ColorChoice::Auto),
            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.12.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.12.0"

to your Cargo.toml

ANSI color and style support

This crate can internally depend on a paris crate to provide support for ANSI color and styles. To use this feature you need to set a paris feature, like this:

[dependencies]
simplelog = { version = "^0.11.0", features = ["paris"] }

in your Cargo.toml

After this you can use e.g. the following call:

info!("I can write <b>bold</b> text or use tags to <red>color it</>");

This will automatically generates terminal control sequences for desired styles.

More formatting info: paris crate 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!

simplelog.rs's People

Contributors

drakulix avatar manio avatar mrkline avatar shimaowo avatar antoyo avatar tekjar avatar chris-stones avatar danielparks avatar djrodgerspryor avatar spearman avatar rusty-snake avatar zjp-cn avatar alexw-gh avatar scvalex avatar horgix avatar anthonyjmartinez avatar hansjorg avatar jacobtread avatar jarrettbillingsley avatar jxs avatar desmondwillowbrook avatar kianmeng avatar vorner avatar lazorchakp avatar rubenvandeven avatar ryankurte avatar samueltardieu avatar softdevca avatar tsidea avatar haluzpav avatar

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.