Crate timber [] [src]

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.");

Macros

timber

Prints timber (processed log). Timber prints time (with microseconds), name of current thread, line number and module name + log text.

Structs

Timber

Timber struct - used as singleton.

Functions

init

Initialize logger by providing output log file. Before call to this method logs will be printed to standard output.

lock

Get locked instance of Timber for guarded loging.

timber

Print formated log.