[−][src]Module safe_app::utils::logging
Logging utilities.
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 main.rs:10] Warning level message.
^ ^ ^ ^ ^ ^
| timestamp | module | message
| | |
| thread name file and line no.
|
level (ERROR, WARN, INFO, DEBUG, or TRACE)
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.
Examples
use log::{error, info}; use std::thread; use safe_core::utils::logging; use unwrap::unwrap; mod my_mod { use log::warn; pub fn show_warning() { warn!("A warning"); } } unwrap!(logging::init(true)); my_mod::show_warning(); let unnamed = thread::spawn(move || info!("Message in unnamed thread")); let _ = unnamed.join(); let _named = unwrap!(thread::Builder::new() .name(String::from("Worker")) .spawn(|| error!("Message in named thread"))); // WARN 16:10:44.989712300 <main> [example::my_mod main.rs:10] A warning // INFO 16:10:44.990716600 <unnamed> [example main.rs:19] Message in unnamed thread // ERROR 16:10:44.991221900 Worker [example main.rs:22] 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
and 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.
Constants
MSG_TERMINATOR | Message terminator for streaming to Log Servers. Servers must look out for this sequence which demarcates the end of a particular log message. |
Functions
init | Initialises the |
init_to_file | Initialises the |
init_to_server | Initialises the |
init_to_web_socket | Initialises the |
init_with_output_file | Initialises the |
validate_web_socket_request | Check that a handshake request has the correct session ID value. |