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/Globals.h | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'src/Globals.h') diff --git a/src/Globals.h b/src/Globals.h index 121dd42d4..778bfe2b9 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -200,46 +200,43 @@ template class SizeChecker; // Common headers (part 1, without macros): #include "fmt.h" #include "StringUtils.h" +#include "LoggerSimple.h" #include "OSSupport/CriticalSection.h" #include "OSSupport/Event.h" #include "OSSupport/File.h" #include "OSSupport/StackTrace.h" -#ifndef TEST_GLOBALS - - #include "LoggerSimple.h" +#ifdef TEST_GLOBALS -#else - #include "fmt/printf.h" + // Basic logging function implementations + namespace Logger + { - // Logging functions - template - void LOG(const char * a_Format, const Args & ... a_Args) + inline void LogFormat( + std::string_view a_Format, eLogLevel, fmt::format_args a_ArgList + ) { - fmt::printf(a_Format, a_Args...); + fmt::vprint(a_Format, a_ArgList); putchar('\n'); fflush(stdout); } - #define LOGERROR LOG - #define LOGWARNING LOG - #define LOGD LOG - #define LOGINFO LOG - #define LOGWARN LOG - - template - void FLOG(const char * a_Format, const Args & ... a_Args) + inline void LogPrintf( + std::string_view a_Format, eLogLevel, fmt::printf_args a_ArgList + ) { - fmt::print(a_Format, a_Args...); + fmt::vprintf(a_Format, a_ArgList); putchar('\n'); fflush(stdout); } - #define FLOGERROR FLOG - #define FLOGWARNING FLOG - #define FLOGD FLOG - #define FLOGINFO FLOG - #define FLOGWARN FLOG + inline void LogSimple(std::string_view a_Message, eLogLevel) + { + fmt::print("{}\n", a_Message); + fflush(stdout); + } + + } // namespace Logger #endif -- cgit v1.2.3