[][src]Crate spirit_log

A spirit configuration helper for logging.

Set of configuration fragments and config helpers for the spirit configuration framework that configures logging for the log crate and updates it as the configuration changes (even at runtime).

Currently, it also allows asking for log output on the command line and multiple logging destinations with different log levels set.

It assumes the application doesn't set the global logger (this crate sets it on its own).

For details about added options, see the Opts and Cfg configuration fragments.


The logging is set in multiple steps:

  • As soon as the config helper is registered, a logging on the WARN level is sent to stderr.
  • After command line arguments are parsed the stderr logging is updated to reflect that (or left on the WARN level if nothing is set by the user).
  • After configuration is loaded from the files, full logging is configured.

Integration with other loggers

If you need something specific (for example sentry), you can provide functions to add additional loggers in parallel with the ones created in this crate. The crate will integrate them all together.

Performance warning

This allows the user to create arbitrary number of loggers. Furthermore, the logging is synchronous and not buffered. When writing a lot of logs or sending them over the network, this could become a bottleneck.

Planned features

These pieces are planned some time in future, but haven't happened yet.

  • Reconnecting to the remote server if a TCP connection is lost.
  • Log file rotation.
  • Setting of logging format (choosing either local or UTC, the format argument or JSON).
  • Colors on stdout/stderr.
  • Async and buffered logging and ability to drop log messages when logging doesn't keep up.


extern crate log;
extern crate spirit;
extern crate spirit_log;
extern crate serde_derive;
extern crate structopt;

use spirit::Spirit;
use spirit_log::{Cfg as LogCfg, Opts as LogOpts};

#[derive(Clone, Debug, StructOpt)]
struct Opts {
    log: LogOpts,

impl Opts {
    fn log(&self) -> LogOpts {

#[derive(Clone, Debug, Default, Deserialize)]
struct Cfg {
    log: LogCfg,

impl Cfg {
    fn log(&self) -> LogCfg {

fn main() {
    Spirit::<Opts, Cfg>::new()
        .config_helper(Cfg::log, Opts::log, "logging")
        .run(|_spirit| {
            info!("Hello world");

The configuration could look something like this:

level = "DEBUG"
type = "file"
filename = "/tmp/example.log"
clock = "UTC"



A configuration fragment to set up logging.


Description of extra configuration for logging.


A fragment for command line options.


This error can be returned when initialization of logging to syslog fails.