summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorShawn Willden <swillden@google.com>2015-05-22 19:58:06 -0600
committerShawn Willden <swillden@google.com>2015-05-26 10:35:48 -0600
commitde7e66c3692073eb967f01cc8281441709701e2d (patch)
tree8f73074c8ddc4f9c323ec8b0bed6685953bc8042 /include
parent58427c44b9261035351d2eee604a299c0b46dbb4 (diff)
downloadandroid_system_keymaster-de7e66c3692073eb967f01cc8281441709701e2d.tar.gz
android_system_keymaster-de7e66c3692073eb967f01cc8281441709701e2d.tar.bz2
android_system_keymaster-de7e66c3692073eb967f01cc8281441709701e2d.zip
Change handling of debug log statments in non-debug builds.
The previous way had a problem when used in statments like: if (foo) LOG_D(...); When built without debugging, this became: if (foo) ; Which is sort of okay, but the compiler complains. The new way also has the advantage that the compiler always sees and checks the log arguments. Given that it ends up compiling something like: do { if (0) Logger::Debug(...); } while (0); It should optimize the entire block out, and should even discard the literal string used for the format. So it's better all around. Change-Id: I895141077f627a2d08dcb0d7d2d0799067a2c957
Diffstat (limited to 'include')
-rw-r--r--include/keymaster/logger.h30
1 files changed, 16 insertions, 14 deletions
diff --git a/include/keymaster/logger.h b/include/keymaster/logger.h
index da7d557..7b9e6d5 100644
--- a/include/keymaster/logger.h
+++ b/include/keymaster/logger.h
@@ -55,24 +55,26 @@ class Logger {
static Logger* instance_;
};
-#ifdef DEBUG
-
#define STR(x) #x
#define STRINGIFY(x) STR(x)
#define FILE_LINE __FILE__ ", Line " STRINGIFY(__LINE__) ": "
-#define LOG_D(fmt, ...) Logger::Debug(FILE_LINE fmt, __VA_ARGS__)
-#define LOG_I(fmt, ...) Logger::Info(FILE_LINE fmt, __VA_ARGS__)
-
-#else // not DEBUG
-
-// For production builds, don't bloat the executable with FILE_LINE strings or DEBUG or INFO log
-// messages.
-#define FILE_LINE
-#define LOG_D(fmt, ...)
-#define LOG_I(fmt, ...)
-
-#endif // not DEBUG
+#ifdef DEBUG
+#define DEBUG_LOGS 1
+#else
+#define DEBUG_LOGS 0
+#endif
+
+#define LOG_D(fmt, ...) \
+ do { \
+ if (DEBUG_LOGS) \
+ Logger::Debug(FILE_LINE fmt, __VA_ARGS__); \
+ } while (0)
+#define LOG_I(fmt, ...) \
+ do { \
+ if (DEBUG_LOGS) \
+ Logger::Info(FILE_LINE fmt, __VA_ARGS__); \
+ } while (0)
#define LOG_W(fmt, ...) Logger::Warning(FILE_LINE fmt, __VA_ARGS__)
#define LOG_E(fmt, ...) Logger::Error(FILE_LINE fmt, __VA_ARGS__)