#log-messages #logging #logger #log #color-scheme #regex

print_logger

Logger that print messages to stdout or stderr

4 releases

new 0.2.1 Oct 27, 2024
0.2.0 Feb 8, 2024
0.1.1 Jan 28, 2024
0.1.0 Jan 28, 2024

#250 in Debugging

Download history 10/week @ 2024-07-05 49/week @ 2024-07-12 16/week @ 2024-07-19 27/week @ 2024-07-26 38/week @ 2024-08-02 4/week @ 2024-08-09 14/week @ 2024-08-16 16/week @ 2024-08-23 3/week @ 2024-08-30 19/week @ 2024-09-06 4/week @ 2024-09-13 27/week @ 2024-09-20 55/week @ 2024-09-27 74/week @ 2024-10-04 84/week @ 2024-10-11 9/week @ 2024-10-18

226 downloads per month
Used in otr

GPL-3.0-or-later

28KB
147 lines

Crates.io (latest) Documentation REUSE status

print_logger

A simple logger that prints messages either to stdout or stderr (depending on the message type). A fixed color scheme is applied.

Simple example

use log::*;
use regex::Regex;

// ...

print_logger::new()
	.targets_by_regex(&[Regex::new(&format!("^{}[::.+]*", module_path!())).unwrap()])
	.level_filter(LevelFilter::Info)
	.init()
	.unwrap();

error!("some failure");

// ...

Module Level Logging

print_logger offers the possibility to restrict components which can log. Many crates use log but you may not want their output in your application. For example hyper makes heavy use of log but when your application receives -vvvvv to enable the trace!() messages you don't want the output of hyper's trace!() level.

To support this print_logger includes two methods:

  1. With targets_by_name a list of log targets (see https://docs.rs/log/latest/log/macro.error.html) can be specified. Only messages for these targets are displayed.

  2. With targets_by_regex a list of regular expressions can be specified. Messages are only displayed if their target matches at least one of these expressions. In the example above only messages from the binary itself but none of its dependencies are displayed (per default the current module is used as target in log messages).

If both lists are given, a message is displayed if its target either is in targets_by_name or if it matches one to the expressions of targets_by_regex. Target names (i.e., per default the actual module path) are displayed at the beginning of the log message if the print_target_filter is greater or equal than the specified level_filter.

License

GNU Public License v3.0

Dependencies

~2.3–10MB
~94K SLoC