Add test_logger as feature to logging (#2586)

## Issue Addressed

Fix #2585

## Proposed Changes

Provide a canonical version of test_logger that can be used
throughout lighthouse.

## Additional Info

This allows tests to conditionally emit logging data by adding
test_logger as the default logger. And then when executing
`cargo test --features logging/test_logger` log output
will be visible:

  wink@3900x:~/lighthouse/common/logging/tests/test-feature-test_logger (Add-test_logger-as-feature-to-logging)
  $ cargo test --features logging/test_logger
      Finished test [unoptimized + debuginfo] target(s) in 0.02s
       Running unittests (target/debug/deps/test_logger-e20115db6a5e3714)

  running 1 test
  Sep 10 12:53:45.212 INFO hi, module: test_logger:8
  test tests::test_fn_with_logging ... ok

  test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Doc-tests test-logger

  running 0 tests

  test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Or, in normal scenarios where logging isn't needed, executing
`cargo test` the log output will not be visible:

  wink@3900x:~/lighthouse/common/logging/tests/test-feature-test_logger (Add-test_logger-as-feature-to-logging)
  $ cargo test
      Finished test [unoptimized + debuginfo] target(s) in 0.02s
       Running unittests (target/debug/deps/test_logger-02e02f8d41e8cf8a)

  running 1 test
  test tests::test_fn_with_logging ... ok

  test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Doc-tests test-logger

  running 0 tests

  test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
This commit is contained in:
Wink Saville
2021-10-06 00:46:07 +00:00
parent 02a646a27d
commit 58870fc6d3
19 changed files with 271 additions and 68 deletions

View File

@@ -1,7 +1,5 @@
use slasher::{
test_utils::{indexed_att, logger},
Config, Error, Slasher,
};
use logging::test_logger;
use slasher::{test_utils::indexed_att, Config, Error, Slasher};
use tempfile::tempdir;
use types::Epoch;
@@ -13,7 +11,7 @@ fn attestation_pruning_empty_wrap_around() {
config.chunk_size = 16;
config.history_length = 16;
let slasher = Slasher::open(config.clone(), logger()).unwrap();
let slasher = Slasher::open(config.clone(), test_logger()).unwrap();
let v = vec![0];
let history_length = config.history_length as u64;
@@ -48,7 +46,7 @@ fn pruning_with_map_full() {
config.history_length = 1024;
config.max_db_size_mbs = 1;
let slasher = Slasher::open(config, logger()).unwrap();
let slasher = Slasher::open(config, test_logger()).unwrap();
let v = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];