Crate std_logger [−] [src]
A crate that holds a logging implementation that logs to standard error and
standard out. It uses standard error for all regular messages and standard
out for requests (when using the REQUEST_TARGET
).
Severity
You can use various envorinment variables to change the severity (log level) of the logs to actually log and which to ignore.
The TRACE
variable sets the severity to the trace, meaning it will log
everything. DEBUG
will set it to debug, one level higher then trace and it
will not log anything with a trace severity. LOG
and LOG_LEVEL
can be
used to set the severity to a specific value, see the log
's package
LevelFilter
enum for available values. If none of these envorinment
variables are found it will default to an information severity.
Logging requests
To log requests a special target is provided, REQUEST_TARGET
, this will
log these message to standard out rather then standard out. This allows for
seperate processing of error messages and requests. See the
REQUEST_TARGET
constant for an example.
Crate features
This crate has two features, both of which are enabled by default, "timestamp" and "log-panic".
Timestamp feature
The "timestamp" feature adds a timestamp infront of every message. It uses
the format defined in RFC3339
with 6 digit nanosecond precision, e.g.
2017-08-21T13:50:53.383553Z
. This means that the timestamp is always
logged in UTC.
Log-panic feature
The "log-panic" feature will log all panics using the error
severity,
rather then using the default panic handler. It will log the panic message
as well as the location and a backtrace, see the log output below for an
example.
[ERROR] panic: thread 'main' panicked at 'oops': examples/panic.rs:24
stack backtrace:
0: 0x106ba8f74 - backtrace::backtrace::trace<closure>
at backtrace-0.3.2/src/backtrace/mod.rs:42
1: 0x106ba49af - backtrace::capture::Backtrace::new::h54d7cfa8f40c5b43
at backtrace-0.3.2/src/capture.rs:64
2: 0x106b9f4e6 - log_panics::init::{{closure}}
at log-panics-1.2.0/src/lib.rs:52
3: 0x106bc6951 - std::panicking::rust_panic_with_hook::h6c19f9ba35264287
at src/libstd/panicking.rs:612
4: 0x106b93146 - std::panicking::begin_panic<&str>
at src/libstd/panicking.rs:572
5: 0x106b93bf1 - panic::main
at examples/panic.rs:24
6: 0x106bc751c - __rust_maybe_catch_panic
at src/libpanic_unwind/lib.rs:98
7: 0x106bc6c08 - std::rt::lang_start::h6f338c4ae2d58bbe
at src/libstd/rt.rs:61
8: 0x106b93c29 - main
If the "timestamp" feature is enable the message will be prefixed with a timestamp as described in the Timestamp feature.
Note
This crate provides only a logging implementation. To do actual logging use
the log
crate and it's various macros.
Constants
REQUEST_TARGET |
The log target to use when logging requests. Using this as a target the message will be logged to standard out. |
Functions
init |
Initialize the logger. Any logs with the target set to |