Module maidsafe_utilities::log [] [src]

Allows initialising the env_logger with a standard message format. These functions can initialise logging for output to stdout only, or to a file and stdout. For more fine-grained control, create a file called log.toml in the root directory of the project, or in the same directory where the executable is. See log4rs docs for details about the format and structure of this file.

An example of a log message is:

WARN 19:33:49.245434200 <main> [example::my_mod] Warning level message.
^           ^             ^              ^         ^                  ^
|       timestamp         |           module       |               message
|                         |                        |
|                    thread name           file and line no.

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 <unnamed>.

The functions can safely be called multiple times concurrently.


extern crate log;
extern crate unwrap;
extern crate maidsafe_utilities;
use std::thread;

mod my_mod {
    pub fn show_warning() {
        warn!("A warning");

fn main() {


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

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

    // WARN 16:10:44.989712300 <main> [example::my_mod] A warning
    // INFO 16:10:44.990716600 <unnamed> [example] Message in unnamed thread
    // ERROR 16:10:44.991221900 Worker [example] Message in named thread

Environment variable RUST_LOG can be set and fine-tuned to get various modules logging to different levels. E.g. RUST_LOG=mod0,mod1=debug,mod2,mod3 will have mod0 & mod1 logging at Debug and more severe levels while mod2 & mod3 logging at default (currently Warn) and more severe levels. RUST_LOG=trace,mod0=error,mod1 is going to change the default log level to Trace and more severe. Thus mod0 will log at Error level and mod1 at Trace and more severe ones.



Message terminator for streaming to Log Servers. Servers must look out for this sequence which demarcates the end of a particular log message.



Initialises the env_logger for output to stdout.


Initialises the env_logger for output to a file and optionally to the console asynchronously.


Initialises the env_logger for output to a server and optionally to the console asynchronously.


Initialises the env_logger for output to a web socket and optionally to the console asynchronously. The log which goes to the web-socket will be both verbose and in JSON as filters should be present in web-servers to manipulate the output/view.


Initialises the env_logger for output to stdout and takes an output file name that will override the log configuration.