Crate simple_logging
source ·Expand description
A simple logger for the log
facade. One
log message is written per line. Each line also includes the time it was
logged, the logging level and the ID of the thread.
Examples
Most users will simply need to call log_to_file()
with the path to the log file and minimum log level:
use log::LevelFilter;
simple_logging::log_to_file("test.log", LevelFilter::Info);
Or use log_to_stderr()
if simply logging to
stderr
:
use log::LevelFilter;
simple_logging::log_to_stderr(LevelFilter::Info);
For more control, log_to()
can be used with an
arbitrary sink implementing
Write
+
Send
+ 'static
:
use log::LevelFilter;
use std::io;
simple_logging::log_to(io::sink(), LevelFilter::Info);
Log format
Each and every log message obeys the following fixed and easily-parsable format:
[<hh>:<mm>:<ss>.<SSS>] (<thread-id>) <level> <message>\n
Where <hh>
denotes hours zero-padded to at least two digits, <mm>
denotes minutes zero-padded to two digits, <ss>
denotes seconds
zero-padded to two digits and <SSS>
denotes miliseconds zero-padded to
three digits. <thread-id>
is an implementation-specific alphanumeric ID.
<level>
is the log level as defined by log::LogLevel
and padded right
with spaces. <message>
is the log message. Note that <message>
is
written to the log as-is, including any embedded newlines.
Errors
Any errors returned by the sink when writing are ignored.
Performance
The logger relies on a global Mutex
to serialize access to the user
supplied sink.