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§

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

Functions§

debug_prefix_fn
Change the debug prefix to a dynamic value.
debug_prefix_str
Change the debug prefix to a new static value.
error_prefix_fn
Change the error prefix to a dynamic value.
error_prefix_str
Change the error prefix to a new static value.
info_prefix_fn
Change the info prefix to a dynamic value.
info_prefix_str
Change the info prefix to a new static value.
set_debug
Enable/disable debug messages.
set_verbose
Enable/disable verbose messages.
warning_prefix_fn
Change the warning prefix to a dynamic value.
warning_prefix_str
Change the warning prefix to a new static value.

Type Aliases§

PrefixFn
Function signature for prefix generators.