Dragon - C++ API
A Computation Graph Virtual Machine Based Deep Learning Framework
logging.h
Go to the documentation of this file.
1 
13 #ifndef DRAGON_UTILS_LOGGING_H_
14 #define DRAGON_UTILS_LOGGING_H_
15 
16 #include <iostream>
17 #include <sstream>
18 
19 namespace dragon {
20 
22 
23 LogSeverity StrToLogSeverity(std::string level);
24 
25 std::string SeverityToStr(LogSeverity severity);
26 
28 
29 int EveryNRegister(const char* file, int line, int severity, int n);
30 
32  public:
33  MessageLogger(const char* file, int line, int severity);
35 
36  std::stringstream& stream() { return stream_; }
37 
38  private:
39  int severity_;
40  std::stringstream stream_;
41  void StripBasename(const std::string &full_path, std::string* filename);
42 };
43 
44 #define FATAL_IF(condition) condition ? MessageLogger("-1", -1, -1).stream() : MessageLogger(__FILE__, __LINE__, FATAL).stream()
45 #define CHECK(condition) FATAL_IF(condition) << "Check failed: "#condition" "
46 #define CHECK_OP(val1,val2,op) \
47  FATAL_IF(val1 op val2) << "Check failed: " #val1 " " #op " " #val2 " " << "(" << val1 <<" vs "<<val2 <<")"
48 #define CHECK_EQ(val1, val2) CHECK_OP(val1, val2, ==)
49 #define CHECK_NE(val1, val2) CHECK_OP(val1, val2, !=)
50 #define CHECK_GT(val1, val2) CHECK_OP(val1, val2, >)
51 #define CHECK_GE(val1, val2) CHECK_OP(val1, val2, >=)
52 #define CHECK_LT(val1, val2) CHECK_OP(val1, val2, <)
53 #define CHECK_LE(val1, val2) CHECK_OP(val1, val2, <=)
54 #define LOG(severity) MessageLogger(__FILE__, __LINE__, severity).stream()
55 #define LOG_IF(severity, condition) if(condition) MessageLogger(__FILE__, __LINE__, severity).stream()
56 #define LOG_EVERY_N(severity, n) MessageLogger(__FILE__, __LINE__, EveryNRegister(__FILE__, __LINE__, severity, n)).stream()
57 
58 } // namespace dragon
59 
60 #endif // DRAGON_UTILS_LOGGING_H_
LogSeverity
Definition: logging.h:21
Definition: logging.h:21
std::stringstream & stream()
Definition: logging.h:36
MessageLogger(const char *file, int line, int severity)
Definition: logging.cc:56
Definition: logging.h:21
LogSeverity StrToLogSeverity(std::string level)
Definition: logging.cc:33
std::string SeverityToStr(LogSeverity severity)
void SetLogDestination(LogSeverity type)
Definition: logging.cc:29
Definition: logging.h:21
Definition: logging.h:21
Definition: logging.h:21
Definition: logging.h:31
int EveryNRegister(const char *file, int line, int severity, int n)
Definition: logging.cc:41
~MessageLogger()
Definition: logging.cc:68
Definition: common.h:41