diff options
Diffstat (limited to 'arm_compute/core/utils/logging/Macros.h')
-rw-r--r-- | arm_compute/core/utils/logging/Macros.h | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/arm_compute/core/utils/logging/Macros.h b/arm_compute/core/utils/logging/Macros.h index 6a1b7611ec..4d5aa5fe2c 100644 --- a/arm_compute/core/utils/logging/Macros.h +++ b/arm_compute/core/utils/logging/Macros.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Arm Limited. + * Copyright (c) 2017-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -30,44 +30,71 @@ #ifdef ARM_COMPUTE_LOGGING_ENABLED +#ifdef __GNUC__ +inline std::string signature_name(const std::string &pretty_func) +{ + const auto scope_op = pretty_func.find("::"); + const auto begin = pretty_func.substr(0, scope_op).rfind(" ") + 1; + const auto end = pretty_func.rfind("(") - begin; + + return pretty_func.substr(begin, end) + "()"; +} +#define ARM_COMPUTE_SIGNATURE_NAME signature_name(__PRETTY_FUNCTION__) +#else /* __GNUC__ */ +#define ARM_COMPUTE_SIGNATURE_NAME (__func__) +#endif /* __GNUC__ */ + #define ARM_COMPUTE_LOG_MSG(logger_name, log_level, msg) \ do \ { \ auto __logger = arm_compute::logging::LoggerRegistry::get().logger(logger_name); \ - if(__logger != nullptr) \ + if (__logger != nullptr) \ { \ __logger->log(log_level, msg); \ } \ - } while(false) + } while (false) + +#define ARM_COMPUTE_LOG_MSG_WITH_FUNCNAME(logger_name, log_level, msg) \ + do \ + { \ + auto __logger = arm_compute::logging::LoggerRegistry::get().logger(logger_name); \ + if (__logger != nullptr) \ + { \ + std::ostringstream s; \ + s << ARM_COMPUTE_SIGNATURE_NAME << " : " << msg; \ + __logger->log(log_level, s.str()); \ + } \ + } while (false) #define ARM_COMPUTE_LOG_MSG_WITH_FORMAT(logger_name, log_level, fmt, ...) \ do \ { \ auto __logger = arm_compute::logging::LoggerRegistry::get().logger(logger_name); \ - if(__logger != nullptr) \ + if (__logger != nullptr) \ { \ size_t size = ::snprintf(nullptr, 0, fmt, __VA_ARGS__) + 1; \ - auto char_str = support::cpp14::make_unique<char[]>(size); \ - ::snprintf(char_str.get(), size, #fmt, __VA_ARGS__); \ + auto char_str = std::make_unique<char[]>(size); \ + ::snprintf(char_str.get(), size, fmt, __VA_ARGS__); \ __logger->log(log_level, std::string(char_str.get(), char_str.get() + size - 1)); \ } \ - } while(false) + } while (false) #define ARM_COMPUTE_LOG_STREAM(logger_name, log_level, stream) \ do \ { \ auto __logger = arm_compute::logging::LoggerRegistry::get().logger(logger_name); \ - if(__logger != nullptr) \ + if (__logger != nullptr) \ { \ std::ostringstream s; \ s << stream; \ __logger->log(log_level, s.str()); \ } \ - } while(false) + } while (false) #else /* ARM_COMPUTE_LOGGING_ENABLED */ #define ARM_COMPUTE_LOG_MSG(logger_name, log_level, msg) +#define ARM_COMPUTE_LOG_MSG_WITH_FUNCNAME(logger_name, log_level, msg) #define ARM_COMPUTE_LOG_MSG_WITH_FORMAT(logger_name, log_level, fmt, ...) #define ARM_COMPUTE_LOG_STREAM(logger_name, log_level, stream) |