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§
- Prefix
Fn - Function signature for prefix generators.