Crate slog [−] [src]
Slog - Structured, composable logging for Rust
Features
- easy to use
- great performance; see: slog bench log
#![no_std]support (withno_stdcargo feature)- hierarchical loggers
- lazily evaluated values
- modular, lightweight and very extensible
- tiny core create that does not pull any other dependencies
- feature-crates for specific functionality
- backward compatibility for standard
logcrate (slog-stdlogcrate)- supports logging-scopes
- using slog in library does not force users of the library to use slog
(but gives benefits); see
crates/example-lib
- drains & output formatting
- filtering
- compile-time log level filter using cargo features (same as in
logcrate) - by level, msg, and any 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-termcrate) - Json (
slog-jsoncrate)- Bunyan (
slog-bunyancrate)
- Bunyan (
- syslog (
slog-syslogcrate) - first class custom drains
- filtering
Advantages over log crate
- extensible -
slogprovides core functionality, and some standard feature-set. But using traits, anyone can easily implement as powerful fully-custom features, publish separately and growslogfeature-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? Withslogdrains 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
logyou would have to repeat this information in every log statement. Inslogit 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
AsyncStreamerdrain, and closures to make your logging fast. - run-time configuration -
AtomicSwitchdrain allows changing logging behavior in the running program. You could use eg. signal handlers to change logging level or logging destinations. Seesignalexample.
Notable details
- By defaut does not compile in trace and debug level records in release builds,
and trace level records in debug builds. This makes
traceanddebuglevel logging records practically free, which should encourage using them freely. - Due to the
macro_ruleslimitation log macros syntax comes in several versions. Seelog!macro, and pay attention to;and,details. - Root drain (passed to
Logger::root) must be one that does not ever return errors, which forces user to pick error handing strategy. You can use.fuse()or.ignore_err()methods fromDrainExtto do it conveniently.
Reexports
pub use ser::{PushLazy, ValueSerializer, Serializer, Serialize}; |
Modules
| ser |
Serialization |
Macros
| crit |
Log critical level record |
| debug |
Log debug level record |
| error |
Log error level record |
| info |
Log info level record |
| log |
Log message of a given level |
| o |
Convenience function for building |
| slog_crit |
Log critical level record (alias) |
| slog_debug |
Log debug level record (alias) |
| slog_error |
Log error level record |
| slog_info |
Log info level record (alias) |
| slog_log |
Log message of a given level (alias) |
| slog_trace |
Log trace level record (alias) |
| slog_warn |
Log warning level record (alias) |
| trace |
Log trace level record |
| warn |
Log warning level record |
Structs
| Discard |
Drain discarding everything |
| Duplicate |
Drain duplicating records to two sub-drains |
| Failover |
Failover drain |
| Filter |
Drain filtering records |
| Fuse |
Panicking fuse |
| IgnoreErr |
Error ignoring fuse |
| LevelFilter |
Record log level filter |
| Logger |
Logger |
| MapError |
Map error of a |
| OwnedKeyValueList |
Chain of |
| OwnedKeyValueListIterator |
Iterator over |
| Record |
Logging record |
Enums
| DuplicateError |
Logging error from |
| FilterLevel |
Logging filtering level |
| Level |
Log record level |
Statics
| LOG_LEVEL_NAMES |
Official capitalized logging (and logging filtering) level names |
| LOG_LEVEL_SHORT_NAMES |
Official capitalized logging (and logging filtering) short level names |
Traits
| Drain |
Logging drain |
| DrainExt |
Convenience methods |
Functions
| discard |
Discard all logging records |
| duplicate |
Duplicate records to two drains |
| failover |
Failover logging to secondary drain on primary's failure |
| filter |
Filter by |
| fuse |
Panic if the subdrain returns an error. |
| ignore_err |
Ignore any errors returned by the subdrain |
| level_filter |
Filter by log level |
Type Definitions
| BorrowedKeyValue |
Key value pair that can be part of a logging record |
| OwnedKeyValue |
Key value pair that can be owned by |