2 unstable releases

Uses old Rust 2015

0.1.0 Jun 10, 2017
0.0.1 May 28, 2017

#138 in #logs

Download history 24/week @ 2024-03-11 34/week @ 2024-03-18 46/week @ 2024-03-25 95/week @ 2024-04-01 16/week @ 2024-04-08 27/week @ 2024-04-15 31/week @ 2024-04-22 20/week @ 2024-04-29 26/week @ 2024-05-06 28/week @ 2024-05-13 25/week @ 2024-05-20 22/week @ 2024-05-27 21/week @ 2024-06-03 24/week @ 2024-06-10 19/week @ 2024-06-17 30/week @ 2024-06-24

94 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