2 unstable releases

Uses old Rust 2015

0.1.0 Jun 10, 2017
0.0.1 May 28, 2017

#125 in #logs

35 downloads per month
Used in 10 crates (8 directly)

MIT license

8KB
79 lines

Timber is simple logger facility. It provides means to write logs to given file in concurrent applications.

timber! macro takes as argument level number and writes log only if it is greater than zero. If user defines log levels as constants compiler will be able to ignore strings passed to unused logs and make application smaller. This way user can keep set of debugging logs, but compile them out for release.

By default timber writes logs to stdout. To write to a file one have to pass file path with timber::init(path).

Example wrapper for timber could look like:

#[macro_use(timber)]
use timber;

#[cfg(debug)]
pub mod level {
    pub const ERR: i32 = 1;
    pub const DEB: i32 = 2;
    pub const INF: i32 = 7;
}

#[cfg(not(debug))]
pub mod level {
    pub const ERR: i32 = 1;
    pub const DEB: i32 = 0;
    pub const INF: i32 = 3;
}

macro_rules! log_err{($($arg:tt)*) => {timber!($crate::level::ERR, "ERR", $($arg)*)}}
macro_rules! log_deb{($($arg:tt)*) => {timber!($crate::level::DEB, "DEB", $($arg)*)}}
macro_rules! log_inf{($($arg:tt)*) => {timber!($crate::level::INF, "INF", $($arg)*)}}

//log_err!("This is error! I'm visible!");
//log_deb!("I'm debug. I'm visible only in debug mode.");

Dependencies

~0.6–1MB
~15K SLoC