From 44b91534c2398b6c9b3c1b49cc7837d64ca6ba37 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Fri, 5 Jun 2020 14:01:40 -0300 Subject: [PATCH] Made `log()` callable publicly This allows use of some free functions within lokimq that can still log (assuming they have a LokiMQ reference). --- lokimq/auth.cpp | 2 +- lokimq/lokimq-internal.h | 5 ++--- lokimq/lokimq.h | 10 +++++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lokimq/auth.cpp b/lokimq/auth.cpp index cd5fd98..90a7814 100644 --- a/lokimq/auth.cpp +++ b/lokimq/auth.cpp @@ -204,7 +204,7 @@ void LokiMQ::process_zap_requests() { else o << v; } - log_(LogLevel::trace, __FILE__, __LINE__, o.str()); + log(LogLevel::trace, __FILE__, __LINE__, o.str()); } else #endif LMQ_LOG(debug, "Processing ZAP authentication request"); diff --git a/lokimq/lokimq-internal.h b/lokimq/lokimq-internal.h index 4dfe7b6..005a640 100644 --- a/lokimq/lokimq-internal.h +++ b/lokimq/lokimq-internal.h @@ -4,12 +4,11 @@ // Inside some method: // LMQ_LOG(warn, "bad ", 42, " stuff"); // -// (The "this->" is here to work around gcc 5 bugginess when called in a `this`-capturing lambda.) -#define LMQ_LOG(level, ...) this->log_(LogLevel::level, __FILE__, __LINE__, __VA_ARGS__) +#define LMQ_LOG(level, ...) log(LogLevel::level, __FILE__, __LINE__, __VA_ARGS__) #ifndef NDEBUG // Same as LMQ_LOG(trace, ...) when not doing a release build; nothing under a release build. -# define LMQ_TRACE(...) this->log_(LogLevel::trace, __FILE__, __LINE__, __VA_ARGS__) +# define LMQ_TRACE(...) log(LogLevel::trace, __FILE__, __LINE__, __VA_ARGS__) #else # define LMQ_TRACE(...) #endif diff --git a/lokimq/lokimq.h b/lokimq/lokimq.h index ce2e589..a88e035 100644 --- a/lokimq/lokimq.h +++ b/lokimq/lokimq.h @@ -268,6 +268,10 @@ public: /// to direct very simple batch completion jobs to be executed directly in the proxy thread. inline static const TaggedThread run_in_proxy{"_proxy", -1}; + /// Writes a message to the logging system; intended mostly for internal use. + template + void log(LogLevel lvl, const char* filename, int line, const T&... stuff); + private: /// The lookup function that tells us where to connect to a peer, or empty if not found. @@ -280,10 +284,6 @@ private: /// The callback to call with log messages Logger logger; - /// Logging implementation - template - void log_(LogLevel lvl, const char* filename, int line, const T&... stuff); - /////////////////////////////////////////////////////////////////////////////////// /// NB: The following are all the domain of the proxy thread (once it is started)! @@ -1433,7 +1433,7 @@ inline std::string_view trim_log_filename(std::string_view local_file) { } template -void LokiMQ::log_(LogLevel lvl, const char* file, int line, const T&... stuff) { +void LokiMQ::log(LogLevel lvl, const char* file, int line, const T&... stuff) { if (log_level() < lvl) return;