2 releases

0.1.1-beta.1 Oct 4, 2020
0.1.0 Sep 23, 2020

#102 in #log-level

MIT license

17KB
356 lines

SELog

crates.io docs.rs Downloads Downloads (latest) License

Simple, Easy LOGger logs to StdErr.

Documents

API Documents are available on docs.rs.

License

SELog is licensed under the MIT license.

See LICENSE for details.


lib.rs:

Simple, Easy LOGger logs to StdErr.

CAUTION: This crate is compatible with log ^0.4.11.

This crate provides a simple, minimal and easy to use implementation of log crate.

Example

Simple Use Case

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

use selog::SELog;

fn main() {
    SELog::new().init().unwrap();

    error!("Failed something");

    // ..
}

Using clap

Tested on clap 3.0.0-beta.2

#[macro_use]
extern crate log;
extern crate clap;
extern crate selog;

use clap::Clap;
use selog::{Colorize, SELevel, SELog};

#[derive(Clap)]
struct Opts {
    #[clap(short, long, about = "More verbose output.")]
    verbose: bool,
    #[clap(short, long, about = "Less output.")]
    quiet: bool,
    #[clap(short, long, about = "Output debug log.")]
    debug: bool,
    #[clap(long, about = "Control color of output.",
           possible_values = &["off", "auto", "on"],
           default_value = "auto")]
    color: Colorize,
    // Your options...
}

fn main() {
    let opts = Opts::parse();

    SELog::new()
        .level(
            SELevel::new()
                .verbose(opts.verbose)
                .quiet(opts.quiet)
                .debug(opts.debug),
        )
        .colorize(opts.color)
        .init()
        .unwrap();

    error!("Failed something.");

    // ...
}

with opts feature:

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

use selog::{Colorize, SELevel, SELog};

opts! {
    struct Opts {
        // Your options...
    }
}

fn main() {
    let opts = Opts::parse();

    opts.init_log().unwrap();

    error!("Failed something.");

    // ...
}

Dependencies

~0.1–7MB
~36K SLoC