24 #ifndef SINGA_UTILS_LOGGING_H_ 25 #define SINGA_UTILS_LOGGING_H_ 31 #include <glog/logging.h> 49 const int WARNING = 1;
52 const int NUM_SEVERITIES = 4;
57 class LogMessage :
public std::basic_ostringstream<char> {
59 LogMessage(
const char* fname,
int line,
int severity);
63 void GenerateLogMessage();
64 void DoLogging(FILE* file,
const struct tm& tm_time);
80 #define _SINGA_LOG_INFO \ 81 ::singa::logging::LogMessage(__FILE__, __LINE__, singa::INFO) 82 #define _SINGA_LOG_WARNING \ 83 ::singa::logging::LogMessage(__FILE__, __LINE__, singa::WARNING) 84 #define _SINGA_LOG_ERROR \ 85 ::singa::logging::LogMessage(__FILE__, __LINE__, singa::ERROR) 86 #define _SINGA_LOG_FATAL \ 87 ::singa::logging::LogMessageFatal(__FILE__, __LINE__) 89 #define LOG(severity) _SINGA_LOG_##severity 95 #define CHECK(condition) \ 97 LOG(FATAL) << "Check failed: " #condition " " 102 template <
typename T>
103 inline const T& GetReferenceableValue(
const T& t) {
106 inline char GetReferenceableValue(
char t) {
return t; }
107 inline unsigned char GetReferenceableValue(
unsigned char t) {
return t; }
108 inline signed char GetReferenceableValue(
signed char t) {
return t; }
109 inline short GetReferenceableValue(
short t) {
return t; }
110 inline unsigned short GetReferenceableValue(
unsigned short t) {
return t; }
111 inline int GetReferenceableValue(
int t) {
return t; }
112 inline unsigned int GetReferenceableValue(
unsigned int t) {
return t; }
113 inline long GetReferenceableValue(
long t) {
return t; }
114 inline unsigned long GetReferenceableValue(
unsigned long t) {
return t; }
115 inline long long GetReferenceableValue(
long long t) {
return t; }
116 inline unsigned long long GetReferenceableValue(
unsigned long long t) {
122 template <
typename T>
123 inline void MakeCheckOpValueString(std::ostream* os,
const T& v) {
130 void MakeCheckOpValueString(std::ostream* os,
const char& v);
132 void MakeCheckOpValueString(std::ostream* os,
const signed char& v);
134 void MakeCheckOpValueString(std::ostream* os,
const unsigned char& v);
138 void MakeCheckOpValueString(std::ostream* os,
const std::nullptr_t& p);
146 operator bool()
const {
return str_ != NULL; }
151 template <
typename T1,
typename T2>
152 string* MakeCheckOpString(
const T1& v1,
const T2& v2,
153 const char* exprtext);
168 std::ostream* ForVar1() {
return stream_; }
170 std::ostream* ForVar2();
175 std::ostringstream* stream_;
178 template <
typename T1,
typename T2>
179 string* MakeCheckOpString(
const T1& v1,
const T2& v2,
const char* exprtext) {
181 MakeCheckOpValueString(comb.ForVar1(), v1);
182 MakeCheckOpValueString(comb.ForVar2(), v2);
183 return comb.NewString();
190 #define SINGA_DEFINE_CHECK_OP_IMPL(name, op) \ 191 template <typename T1, typename T2> \ 192 inline string* name##Impl(const T1& v1, const T2& v2, \ 193 const char* exprtext) { \ 197 return ::singa::logging::MakeCheckOpString(v1, v2, exprtext); \ 199 inline string* name##Impl(int v1, int v2, const char* exprtext) { \ 200 return name##Impl<int, int>(v1, v2, exprtext); \ 207 SINGA_DEFINE_CHECK_OP_IMPL(Check_EQ,
209 SINGA_DEFINE_CHECK_OP_IMPL(Check_NE, != )
210 SINGA_DEFINE_CHECK_OP_IMPL(Check_LE, <= )
211 SINGA_DEFINE_CHECK_OP_IMPL(Check_LT, < )
212 SINGA_DEFINE_CHECK_OP_IMPL(Check_GE, >= )
213 SINGA_DEFINE_CHECK_OP_IMPL(Check_GT, > )
214 #undef SINGA_DEFINE_CHECK_OP_IMPL 218 #define CHECK_OP_LOG(name, op, val1, val2) \ 219 while (::singa::logging::CheckOpString _result = \ 220 ::singa::logging::name##Impl( \ 221 ::singa::logging::GetReferenceableValue(val1), \ 222 ::singa::logging::GetReferenceableValue(val2), \ 223 #val1 " " #op " " #val2)) \ 224 ::singa::logging::LogMessageFatal(__FILE__, __LINE__) << *(_result.str_) 226 #define CHECK_OP(name, op, val1, val2) CHECK_OP_LOG(name, op, val1, val2) 229 #define CHECK_EQ(val1, val2) CHECK_OP(Check_EQ, ==, val1, val2) 230 #define CHECK_NE(val1, val2) CHECK_OP(Check_NE, !=, val1, val2) 231 #define CHECK_LE(val1, val2) CHECK_OP(Check_LE, <=, val1, val2) 232 #define CHECK_LT(val1, val2) CHECK_OP(Check_LT, <, val1, val2) 233 #define CHECK_GE(val1, val2) CHECK_OP(Check_GE, >=, val1, val2) 234 #define CHECK_GT(val1, val2) CHECK_OP(Check_GT, >, val1, val2) 235 #define CHECK_NOTNULL(val) \ 236 ::singa::logging::CheckNotNull(__FILE__, __LINE__, \ 237 "'" #val "' Must be non NULL", (val)) 241 #define DCHECK(condition) CHECK(condition) 242 #define DCHECK_EQ(val1, val2) CHECK_EQ(val1, val2) 243 #define DCHECK_NE(val1, val2) CHECK_NE(val1, val2) 244 #define DCHECK_LE(val1, val2) CHECK_LE(val1, val2) 245 #define DCHECK_LT(val1, val2) CHECK_LT(val1, val2) 246 #define DCHECK_GE(val1, val2) CHECK_GE(val1, val2) 247 #define DCHECK_GT(val1, val2) CHECK_GT(val1, val2) 251 #define DCHECK(condition) \ 252 while (false && (condition)) LOG(FATAL) 258 #define _SINGA_DCHECK_NOP(x, y) \ 259 while (false && ((void)(x), (void)(y), 0)) LOG(FATAL) 261 #define DCHECK_EQ(x, y) _SINGA_DCHECK_NOP(x, y) 262 #define DCHECK_NE(x, y) _SINGA_DCHECK_NOP(x, y) 263 #define DCHECK_LE(x, y) _SINGA_DCHECK_NOP(x, y) 264 #define DCHECK_LT(x, y) _SINGA_DCHECK_NOP(x, y) 265 #define DCHECK_GE(x, y) _SINGA_DCHECK_NOP(x, y) 266 #define DCHECK_GT(x, y) _SINGA_DCHECK_NOP(x, y) 272 #define QCHECK(condition) CHECK(condition) 273 #define QCHECK_EQ(x, y) CHECK_EQ(x, y) 274 #define QCHECK_NE(x, y) CHECK_NE(x, y) 275 #define QCHECK_LE(x, y) CHECK_LE(x, y) 276 #define QCHECK_LT(x, y) CHECK_LT(x, y) 277 #define QCHECK_GE(x, y) CHECK_GE(x, y) 278 #define QCHECK_GT(x, y) CHECK_GT(x, y) 280 template <
typename T>
281 T&& CheckNotNull(
const char* file,
int line,
const char* exprtext, T&& t) {
285 return std::forward<T>(t);
293 #endif // SINGA_UTILS_LOGGING_H_ void LogToStderr()
Make it so that all log messages go only to stderr.
void InitLogging(const char *argv)
Global functions for both glog and built-in log.
Definition: logging.h:161
Definition: logging.h:142
void SetStderrLogging(int severity)
Make it so that all log messages of at least a particular severity are logged to stderr (in addtion t...
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: common.h:48
void SetLogDestination(int severity, const char *path)
Set the file name for logging (and disable logging to stderr)