Module maidsafe_utilities::log [] [src]

Allows initialising the env_logger with a standard message format.

These functions can initialise the env_logger for output to stderr only, or to a file and stderr.

An example of a log message is:

W 19:33:49.245434 <main> [example:src/main.rs:50] Warning level message.
^        ^          ^        ^          ^                    ^
|    timestamp      | top-level module  |                 message
|                   |                   |
|              thread name       file and line no.
|
level (E, W, I, D, or T for error, warn, info, debug or trace respectively)

Logging of the thread name is enabled or disabled via the show_thread_name parameter. If enabled, and the thread executing the log statement is unnamed, the thread name is shown as ???.

The functions can safely be called multiple times concurrently.

Examples

#[macro_use]
extern crate log;
#[macro_use]
extern crate maidsafe_utilities;
use std::thread;
use maidsafe_utilities::thread::RaiiThreadJoiner;

fn main() {
    maidsafe_utilities::log::init(true);

    warn!("A warning");

    let unnamed = thread::spawn(move || info!("Message in unnamed thread"));
    let _ = unnamed.join();

    let _named = RaiiThreadJoiner::new(thread!("Worker",
                     move || error!("Message in named thread")));

    // W 12:24:07.064746 <main> [example:src/main.rs:11] A warning
    // I 12:24:07.065746 ??? [example:src/main.rs:13] Message in unnamed thread
    // E 12:24:07.065746 Worker [example:src/main.rs:16] Message in named thread
}

Functions

init

Initialises the env_logger for output to stderr.

init_to_file

Initialises the env_logger for output to a file and to stderr.