19 #ifndef ION_BASE_LOGGING_H_
20 #define ION_BASE_LOGGING_H_
60 ION_API
void SetBreakHandler(
const std::function<
void()>& break_handler);
68 namespace logging_internal {
79 std::ostream& GetStream();
82 static const std::string CheckMessage(
const char* check_string,
83 const char* expr_string);
87 std::ostringstream stream_;
104 std::ostream& GetStream();
117 std::ostream& GetStream();
121 static void ClearMessages();
124 static bool HasLoggedMessageAt(
const char* file_name,
int line_number);
126 std::unique_ptr<Logger> logger_;
140 std::ostream& GetStream();
143 std::unique_ptr<Logger> logger_;
160 #define ION_LOG(severity) \
161 ::ion::base::logging_internal::NullLogger(::ion::port::severity).GetStream()
164 #define ION_IGNORE_LOG(severity) \
165 ::ion::base::logging_internal::NullLogger(::ion::port::severity).GetStream()
168 #define ION_LOG_ONCE(severity) \
169 ::ion::base::logging_internal::NullLogger(::ion::port::severity).GetStream()
172 #define ION_LOG_EVERY_N_SEC(severity, time) \
173 ::ion::base::logging_internal::NullLogger(::ion::port::severity).GetStream()
178 #define ION_LOG(severity) \
179 ::ion::base::logging_internal::Logger(__FILE__, __LINE__, \
180 ::ion::port::severity).GetStream()
183 #define ION_IGNORE_LOG(severity) \
184 ::ion::base::logging_internal::NullLogger().GetStream()
187 #define ION_LOG_ONCE(severity) \
188 ::ion::base::logging_internal::SingleLogger( \
189 __FILE__, __LINE__, ::ion::port::severity).GetStream()
192 #define ION_LOG_EVERY_N_SEC(severity, time) \
193 ::ion::base::logging_internal::ThrottledLogger( \
194 __FILE__, __LINE__, ::ion::port::severity, time).GetStream()
216 #define LOG(severity) ION_LOG(severity)
219 #define LOG_ONCE(severity) ION_LOG_ONCE(severity)
223 #define LOG_EVERY_N_SEC(severity, time) ION_LOG_EVERY_N_SEC(severity, time)
225 #define DLOG(severity) ION_LOG(severity)
226 #define DLOG_ONCE(severity) ION_LOG_ONCE(severity)
227 #define DLOG_EVERY_N_SEC(severity, time) ION_LOG_EVERY_N_SEC(severity, time)
229 #define DLOG(severity) ION_IGNORE_LOG(severity)
233 #define DLOG_ONCE(severity) ION_IGNORE_LOG(severity)
236 #define DLOG_EVERY_N_SEC(severity, time) ION_IGNORE_LOG(severity)
245 #define ION_LOG_CHECK_MESSAGE(severity, check_type, expr) \
246 LOG(severity) << ::ion::base::logging_internal::Logger::CheckMessage( \
249 #define ION_CHECK(expr) \
253 ION_LOG_CHECK_MESSAGE(FATAL, "CHECK", #expr)
257 #define ION_DCHECK(expr) \
261 ION_LOG_CHECK_MESSAGE(DFATAL, "DCHECK", #expr)
263 #if defined(ION_PLATFORM_WINDOWS)
292 #define ION_DCHECK(expr) \
295 ::ion::base::logging_internal::NullLogger().GetStream()
296 #else // defined(ION_PLATFORM_WINDOWS)
297 #define ION_DCHECK(expr) \
298 if (true || (false && (expr))) \
301 ::ion::base::logging_internal::NullLogger().GetStream()
302 #endif // defined(ION_PLATFORM_WINDOWS)
305 #define ION_CHECK_OP(op, val1, val2) \
306 ION_CHECK((val1) op (val2)) << "(" << (val1) << " " << #op \
307 << " " << (val2) << ")\n"
308 #define ION_DCHECK_OP(op, val1, val2) \
309 ION_DCHECK((val1) op (val2)) << "(" << (val1) << " " << #op \
310 << " " << (val2) << ")\n"
323 #define CHECK(expr) ION_CHECK(expr)
324 #define CHECK_EQ(val1, val2) ION_CHECK_OP(==, val1, val2) // NOLINT
325 #define CHECK_NE(val1, val2) ION_CHECK_OP(!=, val1, val2) // NOLINT
326 #define CHECK_LE(val1, val2) ION_CHECK_OP(<=, val1, val2) // NOLINT
327 #define CHECK_LT(val1, val2) ION_CHECK_OP(<, val1, val2) // NOLINT
328 #define CHECK_GE(val1, val2) ION_CHECK_OP(>=, val1, val2) // NOLINT
329 #define CHECK_GT(val1, val2) ION_CHECK_OP(>, val1, val2) // NOLINT
331 #define DCHECK(expr) ION_DCHECK(expr)
332 #define DCHECK_EQ(val1, val2) ION_DCHECK_OP(==, val1, val2) // NOLINT
333 #define DCHECK_NE(val1, val2) ION_DCHECK_OP(!=, val1, val2) // NOLINT
334 #define DCHECK_LE(val1, val2) ION_DCHECK_OP(<=, val1, val2) // NOLINT
335 #define DCHECK_LT(val1, val2) ION_DCHECK_OP(<, val1, val2) // NOLINT
336 #define DCHECK_GE(val1, val2) ION_DCHECK_OP(>=, val1, val2) // NOLINT
337 #define DCHECK_GT(val1, val2) ION_DCHECK_OP(>, val1, val2) // NOLINT
341 namespace logging_internal {
345 template <
typename T>
353 template <
typename T>
358 template <
typename T>
370 template <
typename T>
382 #define CHECK_NOTNULL(val) \
383 ::ion::base::logging_internal::CheckNotNull(\
384 "'" #val "' Must be non NULL", (val))
388 #endif // ION_BASE_LOGGING_H_
This class prints a message only if the passed file_name and line_number has not printed a message in...
static const std::string CheckMessage(const char *check_string, const char *expr_string)
Returns a message that can be used in CHECK or DCHECK output.
#define ION_LOG(severity)
Completely disable logging in production builds.
port::LogEntryWriter * GetDefaultLogEntryWriter()
Returns the log-writer that messages will be logged to if if another is not explicitly specified via ...
T & CheckNotNullCommon(const char *expr_string, T &t)
Helpers for CHECK_NOTNULL().
T * CheckNotNull(const char *expr_string, T *t)
NullLogger()
Constructs a NullLogger that does nothing.
port::LogEntryWriter * GetLogEntryWriter()
Returns the log-writer that messages are currently logged to.
This class is used to disable logging, while still allowing for log messages to contain '<<' expres...
This class prints a message only the first time it is created for the passed file_name and line_numbe...
void RestoreDefaultBreakHandler()
Restores the default break handler (port::BreakAndAbort).
void SetLogEntryWriter(port::LogEntryWriter *w)
Public functions.
void SetBreakHandler(const std::function< void()> &break_handler)
Sets a custom break handler that gets invoked by Logger::CheckMessage.
This class is used for regular logging.