Crate slog [] [src]

Slog - Structured, extensible, composable logging for Rust

slog-rs is an ecosystem of reusable components for structured, extensible, composable logging for Rust.

slog is slog-rs's main crate providing core components shared between all other parts of slog-rs ecosystem.

This is automatically generated technical documentation of slog. For information about project organization, development, help, etc. please see slog github page

This is documentation for development release of slog v2. See slog v1 documentation for previous stable release.

Core advantages over log crate

  • extensible - slog crate provides core functionality: very basic and portable standard feature-set based on open traits. This allows implementing new features that can be independently published.
  • composable - traits that slog exposes to provide extensibility are designed to be easy to efficiently reuse and combine. By combining different functionalities every application can specify when, where and how exactly log data.
  • structured - Logging with slog is not based on just one global logger. slog's Loggers carry chain of key-value data that contains the context of logging - information that otherwise would have to be repeated in every logging statement.
  • both human and machine readable - By keeping the key-value data format and retaining it's type information, meaning of logging data is preserved. Data can be serialized to machine readable formats like JSON and send it to data-mining system for further analysis etc. On the other hand, when presenting on screen, logging information can be presented in aesthetically pleasing and easy to understand way.

slog features

  • performance oriented; read what makes slog fast and see: slog bench log
    • lazily evaluation through closure values
    • async IO support included: see slog-async crate
  • #![no_std] support (with opt-out std cargo feature flag)
  • tree-structured loggers
  • modular, lightweight and very extensible
    • tiny core crate that does not pull any dependencies
    • feature-crates for specific functionality
    • using slog in library does not force users of the library to use slog (but provides additional functionality); see example how to use slog in library
  • backward and forward compatibility with log crate: see slog-stdlog crate
  • convenience crates:
  • many existing core&community provided features:

Notable details

Note: At compile time slog by default removes trace and debug level statements in release builds, and trace level records in debug builds. This makes trace and debug level logging records practically free, which should encourage using them freely. If you want to enable trace/debug messages or raise the compile time logging level limit, use the following in your Cargo.toml:

slog = { version = ... ,
         features = ["max_level_trace", "release_max_level_warn"] }

Due to the macro_rules limitation log macros syntax comes in several variants. See log! macro, and pay attention to ; and , details.

Root drain (passed to Logger::root) must be one that does not ever return errors. This forces user to pick error handing strategy. Drain::fuse() or Drain::ignore_err().

Where to start

Drain, Logger and log macro are the most important elements of slog.

Examples & help

Some slog-rs examples are maintained in slog-misc repository

slog-rs wiki pages contain some pages about slog-rs technical details.

Source code o other software using slog-rs can be an useful reference.

Visit slog-rs gitter channel for immediate help.

Modules

ser [
Deprecated
]

Compatibility name to ease upgrading from slog v1

Macros

b

Macro for building group of key-value pairs in BorrowedKV

crit

Log critical level record

debug

Log debug level record

error

Log error level record

info

Log info level record

log

Log message a logging record

o

Macro for building group of key-value pairs: OwnedKV

record

Create Record at the given code location

record_static

Create RecordStatic at the given code location

slog_b

Alias of b

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 a logging record (alias)

slog_o

Macro for building group of key-value pairs (alias)

slog_record

Create Record at the given code location (alias)

slog_record_static

Create RecordStatic at the given code location (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

BorrowedKV

Borrowed KV

Discard

Drain discarding everything

Duplicate

Drain duplicating records into two other Drains

Filter

Drain filtering records

FnValue

Explicit lazy-closure Value

Fuse

Drain panicking on error

IgnoreResult

Drain ignoring result

LevelFilter

Drain filtering records by Record logging level

Logger

Logging handle used to execute logging statements

MapError

Drain mapping error returned by another Drain

OwnedKV

Owned KV

OwnedKVList

Chain of SyncMultiSerialize-s of a Logger and its ancestors

PushFnSerializer

Handle passed to PushFnValue closure

PushFnValue

Lazy Value that writes to Serializer

Record

One logging record

SingleKV

Single pair Key and Value

Enums

Error

Serialization Error

FilterLevel

Logging filtering level

Level

Logging level associated with a logging Record

MutexDrainError

Error returned by Mutex<D : Drain>

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

KV

Key-value pair(s)

Serializer

Serializer

Value

Value that can be serialized

Type Definitions

Key

Key type (alias for &'static str)

OwnedKeyValueList [
Deprecated
]

Compatibility name to ease upgrading from slog v1

PushLazy [
Deprecated
]

Compatibility name to ease upgrading from slog v1

Result

Serialization Result

Serialize [
Deprecated
]

Compatibility name to ease upgrading from slog v1

ValueSerializer [
Deprecated
]

Compatibility name to ease upgrading from slog v1