diff options
| author | Dan Engelbrecht <[email protected]> | 2023-09-08 09:47:35 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-08 15:47:35 +0200 |
| commit | f2aab0df9fc96162e603eaa50922369de81a0447 (patch) | |
| tree | c5759c21832537b02838951566f9cbda4f6b99b2 /src | |
| parent | multithread file realization in oplog-mirror (#388) (diff) | |
| download | zen-f2aab0df9fc96162e603eaa50922369de81a0447.tar.xz zen-f2aab0df9fc96162e603eaa50922369de81a0447.zip | |
add console logging to zen command (#389)
properly set trace log level if IsVerbose
add log category to http client
Diffstat (limited to 'src')
| -rw-r--r-- | src/zen/zen.cpp | 16 | ||||
| -rw-r--r-- | src/zenhttp/httpclient.cpp | 14 | ||||
| -rw-r--r-- | src/zenhttp/include/zenhttp/httpclient.h | 8 |
3 files changed, 33 insertions, 5 deletions
diff --git a/src/zen/zen.cpp b/src/zen/zen.cpp index 10478cf44..0ed9226fc 100644 --- a/src/zen/zen.cpp +++ b/src/zen/zen.cpp @@ -34,6 +34,7 @@ ZEN_THIRD_PARTY_INCLUDES_START #include <cpr/cpr.h> +#include <spdlog/sinks/ansicolor_sink.h> #include <gsl/gsl-lite.hpp> ZEN_THIRD_PARTY_INCLUDES_END @@ -173,10 +174,19 @@ main(int argc, char** argv) #endif zen::logging::InitializeLogging(); - zen::MaximizeOpenFileCount(); // Set output mode to handle virtual terminal sequences zen::logging::EnableVTMode(); + std::set_terminate([]() { ZEN_CRITICAL("Program exited abnormally via std::terminate()"); }); + + auto& DefaultLogger = zen::logging::Default(); + auto& Sinks = DefaultLogger.sinks(); + + Sinks.clear(); + auto ConsoleSink = std::make_shared<spdlog::sinks::ansicolor_stdout_sink_mt>(); + Sinks.push_back(ConsoleSink); + + zen::MaximizeOpenFileCount(); ////////////////////////////////////////////////////////////////////////// @@ -389,6 +399,10 @@ main(int argc, char** argv) { spdlog::set_level(spdlog::level::debug); } + if (GlobalOptions.IsVerbose) + { + spdlog::set_level(spdlog::level::trace); + } for (const CommandInfo& CmdInfo : Commands) { diff --git a/src/zenhttp/httpclient.cpp b/src/zenhttp/httpclient.cpp index f3a9ad71b..b77b31933 100644 --- a/src/zenhttp/httpclient.cpp +++ b/src/zenhttp/httpclient.cpp @@ -121,7 +121,7 @@ CommonResponse(cpr::Response&& HttpResponse, IoBuffer&& Payload = {}) struct HttpClient::Impl : public RefCounted { - Impl(); + Impl(spdlog::logger& Log); ~Impl(); // Session allocation @@ -169,6 +169,8 @@ struct HttpClient::Impl : public RefCounted return Result; } + spdlog::logger& Logger() { return Outer->Logger(); } + private: Impl* Outer; cpr::Session* CprSession; @@ -183,14 +185,17 @@ struct HttpClient::Impl : public RefCounted const KeyValueMap& AdditionalHeader, const KeyValueMap& Parameters); + spdlog::logger& Logger() { return m_Log; } + private: + spdlog::logger& m_Log; RwLock m_SessionLock; std::vector<cpr::Session*> m_Sessions; void ReleaseSession(cpr::Session*); }; -HttpClient::Impl::Impl() +HttpClient::Impl::Impl(spdlog::logger& Log) : m_Log(Log) { } @@ -420,9 +425,10 @@ private: ////////////////////////////////////////////////////////////////////////// HttpClient::HttpClient(std::string_view BaseUri, const HttpClientSettings& Connectionsettings) -: m_BaseUri(BaseUri) +: m_Log(zen::logging::Get(Connectionsettings.LogCategory)) +, m_BaseUri(BaseUri) , m_ConnectionSettings(Connectionsettings) -, m_Impl(new Impl) +, m_Impl(new Impl(m_Log)) { StringBuilder<32> SessionId; GetSessionId().ToString(SessionId); diff --git a/src/zenhttp/include/zenhttp/httpclient.h b/src/zenhttp/include/zenhttp/httpclient.h index 18031b280..2c81f4a23 100644 --- a/src/zenhttp/include/zenhttp/httpclient.h +++ b/src/zenhttp/include/zenhttp/httpclient.h @@ -11,6 +11,10 @@ #include <optional> #include <unordered_map> +namespace spdlog { +class logger; +} // namespace spdlog + namespace zen { class CbPackage; @@ -28,6 +32,7 @@ class CompositeBuffer; struct HttpClientSettings { + std::string LogCategory = "httpclient"; std::chrono::milliseconds ConnectTimeout{3000}; std::chrono::milliseconds Timeout{}; bool AssumeHttp2 = false; @@ -143,9 +148,12 @@ public: return std::make_pair("Accept", MapContentTypeToString(ContentType)); } + spdlog::logger& Logger() { return m_Log; } + private: struct Impl; + spdlog::logger& m_Log; std::string m_BaseUri; std::string m_SessionId; const HttpClientSettings m_ConnectionSettings; |