Crate mhlog[][src]

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

Change the debug prefix to a dynamic value.

Change the debug prefix to a new static value.

Change the error prefix to a dynamic value.

Change the error prefix to a new static value.

Change the info prefix to a dynamic value.

Change the info prefix to a new static value.

Enable/disable debug messages.

Enable/disable verbose messages.

Change the warning prefix to a dynamic value.

Change the warning prefix to a new static value.

Type Definitions

Function signature for prefix generators.