Browse Source

Configure logging for testutil (#128)

Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
pull/129/head
Dmitriy Khaustov 4 years ago
committed by GitHub
parent
commit
5ddc91034e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      src/log/configurator.cpp
  2. 28
      test/testutil/prepare_loggers.hpp

1
src/log/configurator.cpp

@ -39,7 +39,6 @@ groups:
- name: tls
- name: listener_manager
- name: libp2p_debug
level: trace
# --------------- End of libp2p config ---------------)");
}

28
test/testutil/prepare_loggers.hpp

@ -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);

Loading…
Cancel
Save