From 3189a3cbee8eb9d7ded7605776a75f35e5e2f122 Mon Sep 17 00:00:00 2001 From: Peter Bell Date: Fri, 15 May 2020 03:35:43 +0100 Subject: Update logging code to reduce unnecessary string copying: * Write into a single fmt::memory_buffer * Use string_view instead of AString for listener callbacks * Also collapsed vFLOG and vLOG functions into one per formatting type --- src/Logger.h | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) (limited to 'src/Logger.h') diff --git a/src/Logger.h b/src/Logger.h index e0680e125..ef86b3313 100644 --- a/src/Logger.h +++ b/src/Logger.h @@ -6,19 +6,10 @@ class cLogger { public: - enum eLogLevel - { - llRegular, - llInfo, - llWarning, - llError, - }; - - class cListener { public: - virtual void Log(AString a_Message, eLogLevel a_LogLevel) = 0; + virtual void Log(std::string_view a_Message, eLogLevel a_LogLevel) = 0; virtual ~cListener(){} }; @@ -59,23 +50,17 @@ public: }; /** Log a message formatted with a printf style formatting string. */ - void vLogPrintf(const char * a_Format, eLogLevel a_LogLevel, fmt::printf_args a_ArgList); - template - void LogPrintf(const char * a_Format, eLogLevel a_LogLevel, const Args & ... args) - { - vLogPrintf(a_Format, a_LogLevel, fmt::make_printf_args(args...)); - } + void LogPrintf( + std::string_view a_Format, eLogLevel a_LogLevel, fmt::printf_args a_ArgList + ); /** Log a message formatted with a python style formatting string. */ - void vLogFormat(const char * a_Format, eLogLevel a_LogLevel, fmt::format_args a_ArgList); - template - void LogFormat(const char * a_Format, eLogLevel a_LogLevel, const Args & ... args) - { - vLogFormat(a_Format, a_LogLevel, fmt::make_format_args(args...)); - } + void LogFormat( + std::string_view a_Format, eLogLevel a_LogLevel, fmt::format_args a_ArgList + ); /** Logs the simple text message at the specified log level. */ - void LogSimple(const AString & a_Message, eLogLevel a_LogLevel = llRegular); + void LogSimple(std::string_view a_Message, eLogLevel a_LogLevel = eLogLevel::Regular); cAttachment AttachListener(std::unique_ptr a_Listener); @@ -88,6 +73,7 @@ private: std::vector> m_LogListeners; void DetachListener(cListener * a_Listener); + void LogLine(std::string_view a_Line, eLogLevel a_LogLevel); }; -- cgit v1.2.3