From 317c496b68e037c7831705a05480454c36cb4f5b Mon Sep 17 00:00:00 2001 From: Adam Malinowski Date: Tue, 15 Jul 2014 14:16:20 +0200 Subject: [PATCH] Add conditional logs building This feature is needed for correct building tests when tested units use logging mechanism. Tests should not depend on logger. Change-Id: I110f5f0238726d1110388eaefc028c90747aa747 --- src/common/log/Backtrace.h | 6 +++++- src/common/log/log.h | 16 +++++++++++----- test/CMakeLists.txt | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/common/log/Backtrace.h b/src/common/log/Backtrace.h index b697195..df023ba 100644 --- a/src/common/log/Backtrace.h +++ b/src/common/log/Backtrace.h @@ -25,15 +25,17 @@ #ifndef SRC_COMMON_LOG_BACKTRACE_H_ #define SRC_COMMON_LOG_BACKTRACE_H_ +#ifndef CYNARA_NO_LOGS #define UNW_LOCAL_ONLY #include +#endif #include namespace Cynara { class Backtrace { public: -#ifdef BUILD_TYPE_DEBUG +#if defined(BUILD_TYPE_DEBUG) && !defined(CYNARA_NO_LOGS) static const std::string getBacktrace(void); #else static const std::string getBacktrace(void) { @@ -51,7 +53,9 @@ private: void operator=(Backtrace const &) = delete; const std::string buildBacktrace(void); +#ifndef CYNARA_NO_LOGS void getSourceInfo(unw_word_t proc_address); +#endif private: const char *m_fileName; diff --git a/src/common/log/log.h b/src/common/log/log.h index 6f1eca4..0ed2c3e 100644 --- a/src/common/log/log.h +++ b/src/common/log/log.h @@ -25,15 +25,21 @@ #ifndef CYNARA_COMMON_LOG_H #define CYNARA_COMMON_LOG_H +#ifndef CYNARA_NO_LOGS #include +#endif extern int __log_level; -#define __LOG(LEVEL, ...) \ - do { \ - if(LEVEL <= __log_level) \ - sd_journal_print(LEVEL, __VA_ARGS__); \ - } while (0) +#ifndef CYNARA_NO_LOGS + #define __LOG(LEVEL, ...) \ + do { \ + if(LEVEL <= __log_level) \ + sd_journal_print(LEVEL, __VA_ARGS__); \ + } while (0) +#else + #define __LOG(LEVEL, ...) +#endif #define LEGM(...) __LOG(LOG_EMERG, __VA_ARGS__) /* system is unusable */ #define LOGA(...) __LOG(LOG_ALERT, __VA_ARGS__) /* action must be taken immediately */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0b6f913..52117a5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -37,6 +37,7 @@ SET(CMAKE_CXX_FLAGS_RELEASE "-g -std=c++0x -O2") ADD_DEFINITIONS("-Werror") # Make all warnings into errors. ADD_DEFINITIONS("-Wall") # Generate all warnings ADD_DEFINITIONS("-Wextra") # Generate even more extra warnings +ADD_DEFINITIONS("-DCYNARA_NO_LOGS") # Disable building logs MESSAGE(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") -- 2.7.4