Stop to define DISALLOW_EVIL_CONSTRUCTORS to avoid name conflict.
[platform/upstream/glog.git] / src / glog / raw_logging.h.in
1 // Copyright 2006 Google Inc. All Rights Reserved.
2 // Author: Maxim Lifantsev
3 //
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.
7
8 #ifndef BASE_RAW_LOGGING_H__
9 #define BASE_RAW_LOGGING_H__
10
11 @ac_google_start_namespace@
12
13 #include "glog/log_severity.h"
14 #include "glog/vlog_is_on.h"
15
16 // This is similar to LOG(severity) << format... and VLOG(level) << format..,
17 // but
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
24 // Usage example:
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, ...) \
31   do { \
32     @ac_google_namespace@::RawLog__(@ac_google_namespace@::severity, __FILE__,  __LINE__, __VA_ARGS__); \
33   } while (0)
34
35 #define RAW_VLOG(verboselevel, ...) \
36   do { \
37     if (VLOG_IS_ON(verboselevel)) { \
38       @ac_google_namespace@::RawLog__(@ac_google_namespace@::INFO, __FILE__,  __LINE__, __VA_ARGS__); \
39     } \
40   } while (0)
41
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) \
48   do { \
49     if (!(condition)) { \
50       RAW_LOG(FATAL, "Check %s failed: %s", #condition, message); \
51     } \
52   } while (0)
53
54 // Debug versions of RAW_LOG and RAW_CHECK
55 #ifndef NDEBUG
56
57 #define RAW_DLOG(severity, ...) RAW_LOG(severity, __VA_ARGS__)
58 #define RAW_DCHECK(condition, message) RAW_CHECK(condition, message)
59
60 #else  // NDEBUG
61
62 #define RAW_DLOG(severity, ...) \
63   while (false) \
64     RAW_LOG(severity, __VA_ARGS__)
65 #define RAW_DCHECK(condition, message) \
66   while (false) \
67     RAW_CHECK(condition, message)
68
69 #endif  // NDEBUG
70
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@;
78
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);
84
85 @ac_google_end_namespace@
86
87 #endif  // BASE_RAW_LOGGING_H__