1 // Copyright 2006 Google Inc. All Rights Reserved.
2 // Author: Maxim Lifantsev
4 // Logging routines that do not allocate any memory and acquire any
5 // locks, and can therefore be used by low-level memory allocation
6 // and synchronization code.
8 #ifndef BASE_RAW_LOGGING_H__
9 #define BASE_RAW_LOGGING_H__
11 @ac_google_start_namespace@
13 #include "glog/log_severity.h"
14 #include "glog/vlog_is_on.h"
16 // This is similar to LOG(severity) << format... and VLOG(level) << format..,
18 // * it is to be used ONLY by low-level modules that can't use normal LOG()
19 // * it is desiged to be a low-level logger that does not allocate any
20 // memory and does not need any locks, hence:
21 // * it logs straight and ONLY to STDERR w/o buffering
22 // * it uses an explicit format and arguments list
23 // * it will silently chop off really long message strings
25 // RAW_LOG(ERROR, "Failed foo with %i: %s", status, error);
26 // RAW_VLOG(3, "status is %i", status);
27 // These will print an almost standard log lines like this to stderr only:
28 // E0821 211317 file.cc:123] RAW: Failed foo with 22: bad_file
29 // I0821 211317 file.cc:142] RAW: status is 20
30 #define RAW_LOG(severity, ...) \
32 @ac_google_namespace@::RawLog__(@ac_google_namespace@::severity, __FILE__, __LINE__, __VA_ARGS__); \
35 #define RAW_VLOG(verboselevel, ...) \
37 if (VLOG_IS_ON(verboselevel)) { \
38 @ac_google_namespace@::RawLog__(@ac_google_namespace@::INFO, __FILE__, __LINE__, __VA_ARGS__); \
42 // Similar to CHECK(condition) << message,
43 // but for low-level modules: we use only RAW_LOG that does not allocate memory.
44 // We do not want to provide args list here to encourage this usage:
45 // if (!cond) RAW_LOG(FATAL, "foo ...", hard_to_compute_args);
46 // so that the args are not computed when not needed.
47 #define RAW_CHECK(condition, message) \
50 RAW_LOG(FATAL, "Check %s failed: %s", #condition, message); \
54 // Debug versions of RAW_LOG and RAW_CHECK
57 #define RAW_DLOG(severity, ...) RAW_LOG(severity, __VA_ARGS__)
58 #define RAW_DCHECK(condition, message) RAW_CHECK(condition, message)
62 #define RAW_DLOG(severity, ...) \
64 RAW_LOG(severity, __VA_ARGS__)
65 #define RAW_DCHECK(condition, message) \
67 RAW_CHECK(condition, message)
71 // Helper function to implement RAW_LOG and RAW_VLOG
72 // Logs format... at "severity" level, reporting it
73 // as called from file:line.
74 // This does not allocate memory or acquire locks.
75 void RawLog__(LogSeverity severity, const char* file, int line,
76 const char* format, ...)
77 @ac_cv___attribute___printf_4_5@;
79 // Hack to propagate time information into this module so that
80 // this module does not have to directly call localtime_r(),
81 // which could allocate memory.
82 extern "C" struct ::tm;
83 void RawLog__SetLastTime(const struct ::tm& t);
85 @ac_google_end_namespace@
87 #endif // BASE_RAW_LOGGING_H__