提交 253ace53 编写于 作者: L liuruilong

update log module

上级 0e1891e5
...@@ -45,11 +45,12 @@ namespace paddle_mobile { ...@@ -45,11 +45,12 @@ namespace paddle_mobile {
static std::vector<std::string> logs{"NO", "ERROR ", "WARNING", static std::vector<std::string> logs{"NO", "ERROR ", "WARNING",
"INFO ", "DEBUG ", "DEBUG1 ", "INFO ", "DEBUG ", "DEBUG1 ",
"DEBUG2 ", "DEBUG3 ", "DEBUG4 "}; "DEBUG2 ", "DEBUG3 ", "DEBUG4 "};
struct ToLog; struct ToLog;
struct Print;
struct Print { struct Print {
friend struct ToLog; friend struct ToLog;
template <typename T> Print &operator<<(T const &value) { template <typename T> Print &operator<<(T const &value) {
buffer_ << value; buffer_ << value;
return *this; return *this;
...@@ -100,6 +101,8 @@ namespace paddle_mobile { ...@@ -100,6 +101,8 @@ namespace paddle_mobile {
.str()) .str())
#define DLOG \ #define DLOG \
if (paddle_mobile::kLOG_DEBUG > paddle_mobile::log_level) { \
} else \
paddle_mobile::ToLog( \ paddle_mobile::ToLog( \
paddle_mobile::kLOG_DEBUG, \ paddle_mobile::kLOG_DEBUG, \
(std::stringstream() \ (std::stringstream() \
...@@ -109,6 +112,16 @@ namespace paddle_mobile { ...@@ -109,6 +112,16 @@ namespace paddle_mobile {
.str()) .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 #else
namespace paddle_mobile { namespace paddle_mobile {
...@@ -150,5 +163,10 @@ namespace paddle_mobile { ...@@ -150,5 +163,10 @@ namespace paddle_mobile {
if (true) { \ if (true) { \
} else \ } else \
paddle_mobile::ToLog(paddle_mobile::kLOG_DEBUG) paddle_mobile::ToLog(paddle_mobile::kLOG_DEBUG)
#define LOGF(level, format, ...)
#define DLOGF(format, ...)
} }
#endif #endif
...@@ -19,13 +19,19 @@ SOFTWARE. ...@@ -19,13 +19,19 @@ SOFTWARE.
#include "common/log.h" #include "common/log.h"
int main() { int main() {
LOG(paddle_mobile::kLOG_DEBUG) << "test debug" DLOGF("DASJFDAFJ%d -- %f", 12345, 344.234);
<< " next log"; LOG(paddle_mobile::kLOG_DEBUG) << "test debug" << " next log";
LOG(paddle_mobile::kLOG_DEBUG1) << "test debug1" LOG(paddle_mobile::kLOG_DEBUG1) << "test debug1"
<< " next log"; << " next log";
LOG(paddle_mobile::kLOG_DEBUG2) << "test debug2" LOG(paddle_mobile::kLOG_DEBUG2) << "test debug2"
<< " next log"; << " next log";
DLOG << "test DLOG"; DLOG << "test DLOG";
LOG(paddle_mobile::kLOG_ERROR) << " error occur !"; LOG(paddle_mobile::kLOG_ERROR) << " error occur !";
return 0; return 0;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册