From f9371233eeaf23882673fc17ee51e4635c211209 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Tue, 19 Jul 2022 15:22:38 -0300 Subject: [PATCH] hive fmt/spdlog updates --- llarp/tooling/router_hive.cpp | 6 +++--- pybind/CMakeLists.txt | 1 - pybind/llarp/crypto/types.cpp | 6 +----- pybind/llarp/logger.cpp | 17 ++++++++--------- pybind/llarp/router_contact.cpp | 4 +++- pybind/module.cpp | 4 ++-- 6 files changed, 17 insertions(+), 21 deletions(-) diff --git a/llarp/tooling/router_hive.cpp b/llarp/tooling/router_hive.cpp index d06bd8c97..d58a0608a 100644 --- a/llarp/tooling/router_hive.cpp +++ b/llarp/tooling/router_hive.cpp @@ -26,7 +26,7 @@ namespace tooling auto routerId = llarp::RouterID(context->router->pubkey()); container[routerId] = context; - std::cout << "Generated router with ID " << routerId << std::endl; + fmt::print("Generated router with ID {}\n", routerId); } void @@ -46,9 +46,9 @@ namespace tooling { auto& container = (isRelay ? relays : clients); - for (auto [routerId, ctx] : container) + for (const auto& [routerId, ctx] : container) { - routerMainThreads.emplace_back([=]() { + routerMainThreads.emplace_back([ctx = ctx, isRelay = isRelay]() { ctx->Run(llarp::RuntimeOptions{false, false, isRelay}); }); std::this_thread::sleep_for(2ms); diff --git a/pybind/CMakeLists.txt b/pybind/CMakeLists.txt index c2b46ce6e..c8444599a 100644 --- a/pybind/CMakeLists.txt +++ b/pybind/CMakeLists.txt @@ -18,4 +18,3 @@ pybind11_add_module(pyllarp MODULE ) target_link_libraries(pyllarp PUBLIC liblokinet) target_include_directories(pyllarp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) -add_log_tag(pyllarp) diff --git a/pybind/llarp/crypto/types.cpp b/pybind/llarp/crypto/types.cpp index ffbaaf44b..c866791b7 100644 --- a/pybind/llarp/crypto/types.cpp +++ b/pybind/llarp/crypto/types.cpp @@ -17,11 +17,7 @@ namespace llarp .def("ToPublic", &SecretKey::toPublic); py::class_(mod, "Signature") .def(py::init<>()) - .def("__repr__", [](const Signature sig) -> std::string { - std::stringstream ss; - ss << sig; - return ss.str(); - }); + .def("__repr__", [](const Signature& sig) { return sig.ToHex(); }); } } // namespace llarp diff --git a/pybind/llarp/logger.cpp b/pybind/llarp/logger.cpp index 3df7bea93..891847acf 100644 --- a/pybind/llarp/logger.cpp +++ b/pybind/llarp/logger.cpp @@ -1,12 +1,12 @@ #include #include -#include +#include namespace llarp { struct PyLogger { - std::unique_ptr shutup; + std::optional silenced; }; void @@ -16,15 +16,14 @@ namespace llarp .def(py::init<>()) .def_property( "shutup", - [](PyLogger& self) { return self.shutup != nullptr; }, + [](PyLogger& self) { return self.silenced.has_value(); }, [](PyLogger& self, bool shutup) { - if (self.shutup == nullptr && shutup) + if (shutup and not self.silenced) + self.silenced = llarp::log::get_level_default(); + else if (not shutup and self.silenced) { - self.shutup = std::make_unique(); - } - else if (self.shutup != nullptr && shutup == false) - { - self.shutup.reset(); + llarp::log::reset_level(*self.silenced); + self.silenced.reset(); } }); } diff --git a/pybind/llarp/router_contact.cpp b/pybind/llarp/router_contact.cpp index e80fc2ee2..0597a172d 100644 --- a/pybind/llarp/router_contact.cpp +++ b/pybind/llarp/router_contact.cpp @@ -1,6 +1,8 @@ #include + #include -#include +#include +#include "common.hpp" namespace llarp { diff --git a/pybind/module.cpp b/pybind/module.cpp index ae32bd2b9..d122c19b5 100644 --- a/pybind/module.cpp +++ b/pybind/module.cpp @@ -1,5 +1,5 @@ #include "common.hpp" -#include +#include PYBIND11_MODULE(pyllarp, m) { @@ -20,6 +20,6 @@ PYBIND11_MODULE(pyllarp, m) llarp::path::PathHopConfig_Init(m); llarp::handlers::PyHandler_Init(m); llarp::service::Address_Init(m); - m.def("EnableDebug", []() { llarp::SetLogLevel(llarp::eLogDebug); }); + m.def("EnableDebug", []() { llarp::log::reset_level(llarp::log::Level::debug); }); llarp::Logger_Init(m); }