diff --git a/cmake/Hunter/config.cmake b/cmake/Hunter/config.cmake index 2e307b0c..9e175b16 100644 --- a/cmake/Hunter/config.cmake +++ b/cmake/Hunter/config.cmake @@ -14,3 +14,10 @@ # SHA1 1234567890abcdef1234567890abcdef12345678 # CMAKE_ARGS "CMAKE_VARIABLE=value" # ) + +hunter_config(soralog + URL "https://github.com/xDimon/soralog/archive/8fbddeef627eeb0456910ba92e89a5b4d9cd75ed.tar.gz" + SHA1 "98fa62ef43753ad80b2d64756aaa6fa6a49625c1" + CMAKE_ARGS TESTING=OFF EXAMPLES=OFF EXPOSE_MOCKS=ON + KEEP_PACKAGE_SOURCES + ) diff --git a/example/01-echo/libp2p_echo_client.cpp b/example/01-echo/libp2p_echo_client.cpp index 2f4b46cc..f3ca8c36 100644 --- a/example/01-echo/libp2p_echo_client.cpp +++ b/example/01-echo/libp2p_echo_client.cpp @@ -63,7 +63,11 @@ int main(int argc, char *argv[]) { // prepare log system auto logging_system = std::make_shared( - std::make_shared(logger_config)); + std::make_shared( + // Original LibP2P logging config + std::make_shared(), + // Additional logging config for application + logger_config)); auto r = logging_system->configure(); if (not r.message.empty()) { (r.has_error ? std::cerr : std::cout) << r.message << std::endl; @@ -74,9 +78,9 @@ int main(int argc, char *argv[]) { libp2p::log::setLoggingSystem(logging_system); if (std::getenv("TRACE_DEBUG") != nullptr) { - libp2p::log::setLevelOfGroup("*", soralog::Level::TRACE); + libp2p::log::setLevelOfGroup("main", soralog::Level::TRACE); } else { - libp2p::log::setLevelOfGroup("*", soralog::Level::ERROR); + libp2p::log::setLevelOfGroup("main", soralog::Level::ERROR); } // create Echo protocol object - it implement the logic of both server and diff --git a/example/01-echo/libp2p_echo_server.cpp b/example/01-echo/libp2p_echo_server.cpp index f5f2f849..a0389d47 100644 --- a/example/01-echo/libp2p_echo_server.cpp +++ b/example/01-echo/libp2p_echo_server.cpp @@ -11,9 +11,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -78,7 +78,11 @@ int main(int argc, char **argv) { // prepare log system auto logging_system = std::make_shared( - std::make_shared(logger_config)); + std::make_shared( + // Original LibP2P logging config + std::make_shared(), + // Additional logging config for application + logger_config)); auto r = logging_system->configure(); if (not r.message.empty()) { (r.has_error ? std::cerr : std::cout) << r.message << std::endl; @@ -89,9 +93,9 @@ int main(int argc, char **argv) { libp2p::log::setLoggingSystem(logging_system); if (std::getenv("TRACE_DEBUG") != nullptr) { - libp2p::log::setLevelOfGroup("*", soralog::Level::TRACE); + libp2p::log::setLevelOfGroup("main", soralog::Level::TRACE); } else { - libp2p::log::setLevelOfGroup("*", soralog::Level::ERROR); + libp2p::log::setLevelOfGroup("main", soralog::Level::ERROR); } // resulting PeerId should be diff --git a/example/02-kademlia/rendezvous_chat.cpp b/example/02-kademlia/rendezvous_chat.cpp index 957bdc98..62f38710 100644 --- a/example/02-kademlia/rendezvous_chat.cpp +++ b/example/02-kademlia/rendezvous_chat.cpp @@ -42,7 +42,8 @@ class Session : public std::enable_shared_from_this { } stream_->readSome( - gsl::span(incoming_->data(), incoming_->size()), incoming_->size(), + gsl::span(incoming_->data(), static_cast(incoming_->size())), + incoming_->size(), [self = shared_from_this()](libp2p::outcome::result result) { if (not result) { self->close(); @@ -52,7 +53,8 @@ class Session : public std::enable_shared_from_this { } std::cout << self->stream_->remotePeerId().value().toBase58() << " > " << std::string(self->incoming_->begin(), - self->incoming_->begin() + result.value()); + self->incoming_->begin() + + static_cast(result.value())); std::cout.flush(); self->read(); }); @@ -66,7 +68,8 @@ class Session : public std::enable_shared_from_this { } stream_->write( - gsl::span(buffer->data(), buffer->size()), buffer->size(), + gsl::span(buffer->data(), static_cast(buffer->size())), + buffer->size(), [self = shared_from_this(), buffer](libp2p::outcome::result result) { if (not result) { @@ -77,7 +80,8 @@ class Session : public std::enable_shared_from_this { } std::cout << self->stream_->remotePeerId().value().toBase58() << " < " << std::string(buffer->begin(), - buffer->begin() + result.value()); + buffer->begin() + + static_cast(result.value())); std::cout.flush(); }); return true; @@ -175,7 +179,11 @@ groups: int main(int argc, char *argv[]) { // prepare log system auto logging_system = std::make_shared( - std::make_shared(logger_config)); + std::make_shared( + // Original LibP2P logging config + std::make_shared(), + // Additional logging config for application + logger_config)); auto r = logging_system->configure(); if (not r.message.empty()) { (r.has_error ? std::cerr : std::cout) << r.message << std::endl; @@ -186,9 +194,9 @@ int main(int argc, char *argv[]) { libp2p::log::setLoggingSystem(logging_system); if (std::getenv("TRACE_DEBUG") != nullptr) { - libp2p::log::setLevelOfGroup("*", soralog::Level::TRACE); + libp2p::log::setLevelOfGroup("main", soralog::Level::TRACE); } else { - libp2p::log::setLevelOfGroup("*", soralog::Level::ERROR); + libp2p::log::setLevelOfGroup("main", soralog::Level::ERROR); } // resulting PeerId should be diff --git a/example/03-gossip/gossip_chat_example.cpp b/example/03-gossip/gossip_chat_example.cpp index 6add6d70..7c0608a9 100644 --- a/example/03-gossip/gossip_chat_example.cpp +++ b/example/03-gossip/gossip_chat_example.cpp @@ -9,8 +9,8 @@ #include #include -#include #include +#include #include "console_async_reader.hpp" #include "utility.hpp" @@ -60,7 +60,11 @@ int main(int argc, char *argv[]) { // prepare log system auto logging_system = std::make_shared( - std::make_shared(logger_config)); + std::make_shared( + // Original LibP2P logging config + std::make_shared(), + // Additional logging config for application + logger_config)); auto r = logging_system->configure(); if (not r.message.empty()) { (r.has_error ? std::cerr : std::cout) << r.message << std::endl; @@ -71,9 +75,9 @@ int main(int argc, char *argv[]) { libp2p::log::setLoggingSystem(logging_system); if (std::getenv("TRACE_DEBUG") != nullptr) { - libp2p::log::setLevelOfGroup("*", soralog::Level::TRACE); + libp2p::log::setLevelOfGroup("main", soralog::Level::TRACE); } else { - libp2p::log::setLevelOfGroup("*", soralog::Level::ERROR); + libp2p::log::setLevelOfGroup("main", soralog::Level::ERROR); } // overriding default config to see local messages as well (echo mode) diff --git a/example/03-gossip/utility.cpp b/example/03-gossip/utility.cpp index 41c89d0d..49289e69 100644 --- a/example/03-gossip/utility.cpp +++ b/example/03-gossip/utility.cpp @@ -32,16 +32,16 @@ namespace libp2p::protocol::example::utility { void setupLoggers(char level) { switch (level) { case 'e': - libp2p::log::setLevelOfGroup("*", libp2p::log::Level::ERROR); + libp2p::log::setLevelOfGroup("main", libp2p::log::Level::ERROR); break; case 'w': - libp2p::log::setLevelOfGroup("*", libp2p::log::Level::WARN); + libp2p::log::setLevelOfGroup("main", libp2p::log::Level::WARN); break; case 'd': - libp2p::log::setLevelOfGroup("*", libp2p::log::Level::DEBUG); + libp2p::log::setLevelOfGroup("main", libp2p::log::Level::DEBUG); break; case 't': - libp2p::log::setLevelOfGroup("*", libp2p::log::Level::TRACE); + libp2p::log::setLevelOfGroup("main", libp2p::log::Level::TRACE); break; default: break; diff --git a/example/04-dnstxt/ares_resolver.cpp b/example/04-dnstxt/ares_resolver.cpp index 5f53cf28..9ff6070b 100644 --- a/example/04-dnstxt/ares_resolver.cpp +++ b/example/04-dnstxt/ares_resolver.cpp @@ -32,7 +32,11 @@ groups: int main(int argc, char *argv[]) { // prepare log system auto logging_system = std::make_shared( - std::make_shared(logger_config)); + std::make_shared( + // Original LibP2P logging config + std::make_shared(), + // Additional logging config for application + logger_config)); auto r = logging_system->configure(); if (not r.message.empty()) { (r.has_error ? std::cerr : std::cout) << r.message << std::endl; @@ -43,9 +47,9 @@ int main(int argc, char *argv[]) { libp2p::log::setLoggingSystem(logging_system); if (std::getenv("TRACE_DEBUG") != nullptr) { - libp2p::log::setLevelOfGroup("*", soralog::Level::TRACE); + libp2p::log::setLevelOfGroup("main", soralog::Level::TRACE); } else { - libp2p::log::setLevelOfGroup("*", soralog::Level::ERROR); + libp2p::log::setLevelOfGroup("main", soralog::Level::ERROR); } // create a default Host via an injector diff --git a/include/libp2p/log/logger.hpp b/include/libp2p/log/logger.hpp index be9e6655..49defbdd 100644 --- a/include/libp2p/log/logger.hpp +++ b/include/libp2p/log/logger.hpp @@ -16,6 +16,8 @@ namespace libp2p::log { using Level = soralog::Level; using Logger = std::shared_ptr; + inline const std::string defaultGroupName("libp2p"); + void setLoggingSystem(std::shared_ptr logging_system); [[nodiscard]] Logger createLogger(const std::string &tag); diff --git a/src/basic/scheduler/asio_scheduler_backend.cpp b/src/basic/scheduler/asio_scheduler_backend.cpp index d041e5b8..7bce8680 100644 --- a/src/basic/scheduler/asio_scheduler_backend.cpp +++ b/src/basic/scheduler/asio_scheduler_backend.cpp @@ -36,7 +36,7 @@ namespace libp2p::basic { if (ec) { // this should never happen - auto log = log::createLogger("Scheduler", "*"); + auto log = log::createLogger("Scheduler", "scheduler"); log->critical("cannot set timer: {}", ec.message()); boost::asio::detail::throw_error(ec, "setTimer"); } diff --git a/src/log/configurator.cpp b/src/log/configurator.cpp index 644d4779..055a63a3 100644 --- a/src/log/configurator.cpp +++ b/src/log/configurator.cpp @@ -39,6 +39,7 @@ groups: - name: tls - name: listener_manager - name: libp2p_debug + - name: scheduler # --------------- End of libp2p config ---------------)"); } diff --git a/src/log/logger.cpp b/src/log/logger.cpp index a284ddee..048b12ec 100644 --- a/src/log/logger.cpp +++ b/src/log/logger.cpp @@ -28,7 +28,7 @@ namespace libp2p::log { Logger createLogger(const std::string &tag) { ensure_loger_system_is_initialized(); return std::dynamic_pointer_cast(logging_system_) - ->getLogger(tag, "*"); + ->getLogger(tag, defaultGroupName); } Logger createLogger(const std::string &tag, const std::string &group) { diff --git a/test/testutil/prepare_loggers.hpp b/test/testutil/prepare_loggers.hpp index d655d4ef..9caf43d6 100644 --- a/test/testutil/prepare_loggers.hpp +++ b/test/testutil/prepare_loggers.hpp @@ -46,7 +46,6 @@ groups: std::make_shared(), // Additional logging config for testing testing_log_config)); - auto r = logging_system->configure(); if (r.has_error) { std::cerr << r.message << std::endl; @@ -56,7 +55,7 @@ groups: libp2p::log::setLoggingSystem(logging_system); }); - libp2p::log::setLevelOfGroup("*", level); + libp2p::log::setLevelOfGroup(libp2p::log::defaultGroupName, level); } } // namespace testutil