From 5ac658c8f03e621a4fc9cba13097752773d265cc Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 22 Sep 2022 23:14:46 -0700 Subject: [PATCH] [wpiutil] Logger: Conditionalize around WPI_LOG (#4431) The FMT_STRING() call used in the macro does formatter initialization, overhead that's not required if Log() is not going to be called. --- wpiutil/src/main/native/include/wpi/Logger.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wpiutil/src/main/native/include/wpi/Logger.h b/wpiutil/src/main/native/include/wpi/Logger.h index 4cd2a8625b..00b9902e44 100644 --- a/wpiutil/src/main/native/include/wpi/Logger.h +++ b/wpiutil/src/main/native/include/wpi/Logger.h @@ -60,8 +60,11 @@ class Logger { unsigned int m_min_level = 20; }; -#define WPI_LOG(logger_inst, level, format, ...) \ - (logger_inst).Log(level, __FILE__, __LINE__, FMT_STRING(format), __VA_ARGS__) +#define WPI_LOG(logger_inst, level, format, ...) \ + if ((logger_inst).HasLogger() && level >= (logger_inst).min_level()) { \ + (logger_inst) \ + .Log(level, __FILE__, __LINE__, FMT_STRING(format), __VA_ARGS__); \ + } #define WPI_ERROR(inst, format, ...) \ WPI_LOG(inst, ::wpi::WPI_LOG_ERROR, format, __VA_ARGS__)