Initial windows support. Now we don't have the stacktrace and several unittests.
[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 // Annoying stuff for windows -- makes sure clients can import these functions
17 #ifndef GOOGLE_GLOG_DLL_DECL
18 # ifdef _WIN32
19 #   define GOOGLE_GLOG_DLL_DECL  __declspec(dllimport)
20 # else
21 #   define GOOGLE_GLOG_DLL_DECL
22 # endif
23 #endif
24
25 // This is similar to LOG(severity) << format... and VLOG(level) << format..,
26 // but
27 // * it is to be used ONLY by low-level modules that can't use normal LOG()
28 // * it is desiged to be a low-level logger that does not allocate any
29 //   memory and does not need any locks, hence:
30 // * it logs straight and ONLY to STDERR w/o buffering
31 // * it uses an explicit format and arguments list
32 // * it will silently chop off really long message strings
33 // Usage example:
34 //   RAW_LOG(ERROR, "Failed foo with %i: %s", status, error);
35 //   RAW_VLOG(3, "status is %i", status);
36 // These will print an almost standard log lines like this to stderr only:
37 //   E0821 211317 file.cc:123] RAW: Failed foo with 22: bad_file
38 //   I0821 211317 file.cc:142] RAW: status is 20
39 #define RAW_LOG(severity, ...) \
40   do { \
41     @ac_google_namespace@::RawLog__(@ac_google_namespace@::severity, __FILE__,  __LINE__, __VA_ARGS__); \
42   } while (0)
43
44 #define RAW_VLOG(verboselevel, ...) \
45   do { \
46     if (VLOG_IS_ON(verboselevel)) { \
47       @ac_google_namespace@::RawLog__(@ac_google_namespace@::INFO, __FILE__,  __LINE__, __VA_ARGS__); \
48     } \
49   } while (0)
50
51 // Similar to CHECK(condition) << message,
52 // but for low-level modules: we use only RAW_LOG that does not allocate memory.
53 // We do not want to provide args list here to encourage this usage:
54 //   if (!cond)  RAW_LOG(FATAL, "foo ...", hard_to_compute_args);
55 // so that the args are not computed when not needed.
56 #define RAW_CHECK(condition, message) \
57   do { \
58     if (!(condition)) { \
59       RAW_LOG(FATAL, "Check %s failed: %s", #condition, message); \
60     } \
61   } while (0)
62
63 // Debug versions of RAW_LOG and RAW_CHECK
64 #ifndef NDEBUG
65
66 #define RAW_DLOG(severity, ...) RAW_LOG(severity, __VA_ARGS__)
67 #define RAW_DCHECK(condition, message) RAW_CHECK(condition, message)
68
69 #else  // NDEBUG
70
71 #define RAW_DLOG(severity, ...) \
72   while (false) \
73     RAW_LOG(severity, __VA_ARGS__)
74 #define RAW_DCHECK(condition, message) \
75   while (false) \
76     RAW_CHECK(condition, message)
77
78 #endif  // NDEBUG
79
80 // Helper function to implement RAW_LOG and RAW_VLOG
81 // Logs format... at "severity" level, reporting it
82 // as called from file:line.
83 // This does not allocate memory or acquire locks.
84 GOOGLE_GLOG_DLL_DECL void RawLog__(LogSeverity severity,
85                                    const char* file,
86                                    int line,
87                                    const char* format, ...)
88    @ac_cv___attribute___printf_4_5@;
89
90 // Hack to propagate time information into this module so that
91 // this module does not have to directly call localtime_r(),
92 // which could allocate memory.
93 extern "C" struct ::tm;
94 GOOGLE_GLOG_DLL_DECL void RawLog__SetLastTime(const struct ::tm& t);
95
96 @ac_google_end_namespace@
97
98 #endif  // BASE_RAW_LOGGING_H__