timber 0.1.0

Simple configurable logging
Documentation
  • Coverage
  • 100%
    9 out of 9 items documented1 out of 8 items with examples
  • Size
  • Source code size: 9.03 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.63 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • perceptia/perceptia
    159 5 20
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • darkelement

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