From 253ace53ce0d193b3578c114519550ae1eb4c45c Mon Sep 17 00:00:00 2001 From: liuruilong Date: Thu, 17 May 2018 17:46:38 +0800 Subject: [PATCH] update log module --- src/common/log.h | 20 +++++++++++++++++++- test/unit-test/test_log.cpp | 10 ++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/common/log.h b/src/common/log.h index 4ee17df1f4..c26bfee632 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -45,11 +45,12 @@ namespace paddle_mobile { static std::vector logs{"NO", "ERROR ", "WARNING", "INFO ", "DEBUG ", "DEBUG1 ", "DEBUG2 ", "DEBUG3 ", "DEBUG4 "}; - struct ToLog; + struct Print; struct Print { friend struct ToLog; + template Print &operator<<(T const &value) { buffer_ << value; return *this; @@ -100,6 +101,8 @@ namespace paddle_mobile { .str()) #define DLOG \ + if (paddle_mobile::kLOG_DEBUG > paddle_mobile::log_level) { \ + } else \ paddle_mobile::ToLog( \ paddle_mobile::kLOG_DEBUG, \ (std::stringstream() \ @@ -109,6 +112,16 @@ namespace paddle_mobile { .str()) } +#define LOGF(level, format, ...) \ + if (level > paddle_mobile::log_level) { \ + } else \ + printf(format, ##__VA_ARGS__) + +#define DLOGF(format, ...) \ + if (paddle_mobile::kLOG_DEBUG > paddle_mobile::log_level) { \ + } else \ + printf(format, ##__VA_ARGS__) + #else namespace paddle_mobile { @@ -150,5 +163,10 @@ namespace paddle_mobile { if (true) { \ } else \ paddle_mobile::ToLog(paddle_mobile::kLOG_DEBUG) + +#define LOGF(level, format, ...) + +#define DLOGF(format, ...) } + #endif diff --git a/test/unit-test/test_log.cpp b/test/unit-test/test_log.cpp index 6e366363bc..afedb96644 100644 --- a/test/unit-test/test_log.cpp +++ b/test/unit-test/test_log.cpp @@ -19,13 +19,19 @@ SOFTWARE. #include "common/log.h" int main() { - LOG(paddle_mobile::kLOG_DEBUG) << "test debug" - << " next log"; + DLOGF("DASJFDAFJ%d -- %f", 12345, 344.234); + LOG(paddle_mobile::kLOG_DEBUG) << "test debug" << " next log"; + LOG(paddle_mobile::kLOG_DEBUG1) << "test debug1" << " next log"; + LOG(paddle_mobile::kLOG_DEBUG2) << "test debug2" << " next log"; + DLOG << "test DLOG"; + + LOG(paddle_mobile::kLOG_ERROR) << " error occur !"; + return 0; } -- GitLab