log4rs_test_utils/
lib.rs

1//! This crate aims to solve the headache that often occurs when combining
2//! testing with logging. It is split into two halves depending on your use
3//! case: do you want to log your tests or test your logs?
4//!
5//! # Logging your tests
6//! If you want to log your tests, i.e. set up a logger and capture the results
7//! for debugging your unit and integration tests, then look to
8//! [`test_logging`]. Contents include:
9//! * [`TestConsoleAppender`](test_logging::TestConsoleAppender), an appender
10//!   which ensures logs are actually captured by the default test harness rather
11//!   than spewed all over your lovely console.
12//! * [`init_logging_once`](test_logging::init_logging_once), which ensures
13//!   your logging only gets initialized once, even if many tests are running
14//!   in parallel.
15//! * [`init_logging_once_for`](test_logging::init_logging_once_for), which
16//!   does the same, but automatically creates a sensible config for the given
17//!   targets.
18//!
19//! # Testing your logs
20//! If you want to test your logs, i.e. write tests that make assertions about
21//! your log output, then look to [`log_testing`]. Contents include:
22//! * [`MockAppender`](log_testing::MockAppender), an appender that saves all
23//!   logs to a [`Vec<String>`] for programmatic inspection.
24//! * [`logging_test_setup`](log_testing::logging_test_setup), which handles test
25//!   setup by configuring the logger and serializing all logging tests to make
26//!   sure they don't conflict.
27//! * [`logging_test_setup_mock`](log_testing::logging_test_setup_mock) which does
28//!   the same, but automatically creates a [`MockAppender`](log_testing::MockAppender)
29//!   for you to save even more effort.
30//!
31//! # Features
32//! The two halves of this module are feature-gated, so you can disable anything
33//! you don't want. Both features are enabled by default.
34//!
35//! |    Feature     |           Enables           |
36//! | -------------- | --------------------------- |
37//! | `log_testing`  | the [`log_testing`] module  |
38//! | `test_logging` | the [`test_logging`] module |
39
40mod string_buffer;
41
42/// Requires the `log_testing` feature.
43#[cfg(feature = "log_testing")]
44pub mod log_testing;
45
46/// Requires the `test_logging` feature.
47#[cfg(feature = "test_logging")]
48pub mod test_logging;