slog-rs - Structured, composable logging for Rust
Status & news
slog-rs
is near final 1.0.0 release (see
milestone 1.0).
Testing, feedback, PRs, etc. are very welcome. I'd be also very happy to share the ownership of the project with other people to make it more community-driven.
Long term goal is to make it a go-to logging crate for Rust.
Features
- easy to use
- good performance; see: slog bench log
- hierarchical loggers
- lazily evaluated values
- modular and extensible
- small core create with multiple addon crates (
./crates/
) - compile only what you're actually using
- small core create with multiple addon crates (
- backward compatibility with standard
log
crate (usingslog-stdlog
crate)- supports logging-scopes
- drains & output formatting
- filtering
- compile time log level filter using cargo features (same as in
log
crate) - by level, msg, and other meta-data
slog-envlogger
- port ofenv_logger
- compile time log level filter using cargo features (same as in
- multiple outputs
- asynchronous IO writing
- terminal output, with color support (
slog-term
crate) - Json (
slog-json
crate)- Bunyan (
slog-bunyan
crate)
- Bunyan (
- syslog (
slog-syslog
crate) - first class custom drains
- filtering
Advantages over log
crate
- extensible -
slog
provides core functionality, and some standard feature-set. But using Rust trait system, anyone can easily implement as powerful fully-custom features, publish separately and growslog
feature-set for everyone. - composable - Wouldn't it be nice if you could use
env_logger
, but output authentication messages to syslog, while reporting errors over network in json format? Withslog
drains can reuse other drains! You can combine them together, chain, wrap - you name it. - context aware - It's not just one global logger. Hierarchical
loggers carry information about context of logging. When logging an error
condition, you want to know which resource was being handled, on which
instance of your service, using which source code build, talking with what
peer, etc. In standard
log
you would have to repeat this information in every log statement. Inslog
it will happen automatically. See slog-rs functional overview page to understand better logger and drain hierarchies and log record flow through them. - both human and machine readable - By keeping the key-value data format, meaning of logging data is preserved. Dump your logging to a JSON file, and send it to your data-mining system for further analysis. Don't parse it from lines of text anymore!
- lazy evaluation and asynchronous IO included. Waiting to
finish writing logging information to disk, or spending time calculating
data that will be thrown away at the current logging level, are sources of big
performance waste. Use
AsyncStreamer
drain, and closures to make your logging fast. - run-time configuration -
AtomicSwitch
drain allows changing logging behavior in the running program. You could use eg. signal handlers to change logging level or logging destinations. Seesignal
example.
Terminal output example
Using & help
Code snippet
See examples/features.rs
for full code.
Read Documentation for details and features.
See faq for answers to common questions. If you want to say hi, or need help use #slog-rs gitter.im.
To report a bug or ask for features use github issues.
Building & running
If you need to install Rust (come on, you should have done that long time ago!), use rustup.
In your project
In Cargo.toml:
[dependencies]
slog = "*"
In your main.rs
:
#[macro_use]
extern crate slog;
Alternatives
Please fill an issue if slog does not fill your needs. I will appreciate any feedback. You might look into issue discussing slog-rs alternatives too.