Crate mhlog

Source
Expand description

A tiny, simple, thread-safe logging library. No configuration options, take it or leave it.

Writes log messages to stdout/stderr. The writes are thread-safe.

If any of the mutexes protecting the state data (prefixes values, and verbose and debug values) becomes poisoned it will panic.

Provided logging macros:

err!()
warn!()
info!()
verbose!()
debug!()

§Usage

info!("An info message.");
warn!("A warning message.");
err!("An error message.");

§Custom log prefix

The prefix of the log messages may be changed by the user:

mhlog::info_prefix_str("Info:".to_string());
info!("Hello custom world!");

§Dynamic log prefix

Dynamic log prefixes are also supported:

mhlog::info_prefix_fn(|| format!("[{}]", "INFO"));
info!("Hello dynamic world!");

§Features

§Writing to stdout and stderr

By default err!() and warn!() writes to stderr. The rest writes to stdout.

To force all logging to stderr enable the only_stderr feature:

[dependencies]
mhlog = { version = "*", features = ["only_stderr"] }

Or, to force all logging to stdout enable the only_stdout feature:

[dependencies]
mhlog = { version = "*", features = ["only_stdout"] }

§Coloured log messages

Coloured log messages can be enabled with the colours feature.

[dependencies]
mhlog = { version = "*", features = ["colours"] }

Macros§

  • Print a message with the error prefix and exit with error code 1. See err!()
  • Print a message with the debug prefix if debug printing is enabled.
  • Print a message with the error prefix.
  • Print a message with the info prefix.
  • Print a message with the info prefix if verbose printing is enabled.
  • Print a message with the warning prefix.

Functions§

Type Aliases§

  • Function signature for prefix generators.