|
|
@ -18,8 +18,13 @@ namespace testutil { |
|
|
|
|
|
|
|
void prepareLoggers(soralog::Level level = soralog::Level::INFO) { |
|
|
|
std::call_once(initialized, [] { |
|
|
|
|
|
|
|
auto configurator = std::make_shared<soralog::ConfiguratorFromYAML>(std::string(R"( |
|
|
|
// This is configuration part of logging system for using in tests.
|
|
|
|
// 1. It adds synchronous sink to console
|
|
|
|
// 2. Switches root group to them
|
|
|
|
// 3. Sets verbosity to info level
|
|
|
|
// 4. Add special group for tests
|
|
|
|
auto testing_log_config = std::string(R"( |
|
|
|
# ---- Begin of logging system config addon ---- |
|
|
|
sinks: |
|
|
|
- name: console |
|
|
|
type: console |
|
|
@ -29,18 +34,23 @@ sinks: |
|
|
|
groups: |
|
|
|
- name: libp2p |
|
|
|
sink: console |
|
|
|
level: off |
|
|
|
- name: libp2p_debug |
|
|
|
level: trace |
|
|
|
)")); |
|
|
|
level: info |
|
|
|
children: |
|
|
|
- name: testing |
|
|
|
# ----- End of logging system config addon ----- |
|
|
|
)"); |
|
|
|
|
|
|
|
auto logging_system = |
|
|
|
std::make_shared<soralog::LoggingSystem>(configurator); |
|
|
|
auto logging_system = std::make_shared<soralog::LoggingSystem>( |
|
|
|
std::make_shared<soralog::ConfiguratorFromYAML>( |
|
|
|
// Original LibP2P logging config
|
|
|
|
std::make_shared<libp2p::log::Configurator>(), |
|
|
|
// Additional logging config for testing
|
|
|
|
testing_log_config)); |
|
|
|
|
|
|
|
auto r = logging_system->configure(); |
|
|
|
if (r.has_error) { |
|
|
|
std::cerr << r.message << std::endl; |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
throw std::runtime_error("Can't configure logger system"); |
|
|
|
} |
|
|
|
|
|
|
|
libp2p::log::setLoggingSystem(logging_system); |
|
|
|