37e327f5bea927af3e043381537b7e747c7c7fc9
[platform/upstream/glog.git] / src / windows / glog / raw_logging.h
1 // This file is automatically generated from src/glog/raw_logging.h.in
2 // using src/windows/preprocess.sh.
3 // DO NOT EDIT!
4
5 // Copyright (c) 2006, Google Inc.
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
10 // met:
11 //
12 //     * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //     * Redistributions in binary form must reproduce the above
15 // copyright notice, this list of conditions and the following disclaimer
16 // in the documentation and/or other materials provided with the
17 // distribution.
18 //     * Neither the name of Google Inc. nor the names of its
19 // contributors may be used to endorse or promote products derived from
20 // this software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 //
34 // Author: Maxim Lifantsev
35 //
36 // Thread-safe logging routines that do not allocate any memory or
37 // acquire any locks, and can therefore be used by low-level memory
38 // allocation and synchronization code.
39
40 #ifndef BASE_RAW_LOGGING_H_
41 #define BASE_RAW_LOGGING_H_
42
43 namespace google {
44
45 #include "glog/log_severity.h"
46 #include "glog/vlog_is_on.h"
47
48 // Annoying stuff for windows -- makes sure clients can import these functions
49 #ifndef GOOGLE_GLOG_DLL_DECL
50 # if defined(_WIN32) && !defined(__CYGWIN__)
51 #   define GOOGLE_GLOG_DLL_DECL  __declspec(dllimport)
52 # else
53 #   define GOOGLE_GLOG_DLL_DECL
54 # endif
55 #endif
56
57 // This is similar to LOG(severity) << format... and VLOG(level) << format..,
58 // but
59 // * it is to be used ONLY by low-level modules that can't use normal LOG()
60 // * it is desiged to be a low-level logger that does not allocate any
61 //   memory and does not need any locks, hence:
62 // * it logs straight and ONLY to STDERR w/o buffering
63 // * it uses an explicit format and arguments list
64 // * it will silently chop off really long message strings
65 // Usage example:
66 //   RAW_LOG(ERROR, "Failed foo with %i: %s", status, error);
67 //   RAW_VLOG(3, "status is %i", status);
68 // These will print an almost standard log lines like this to stderr only:
69 //   E0821 211317 file.cc:123] RAW: Failed foo with 22: bad_file
70 //   I0821 211317 file.cc:142] RAW: status is 20
71 #define RAW_LOG(severity, ...) \
72   do { \
73     switch (google::severity) {  \
74       case 0: \
75         RAW_LOG_INFO(__VA_ARGS__); \
76         break; \
77       case 1: \
78         RAW_LOG_WARNING(__VA_ARGS__); \
79         break; \
80       case 2: \
81         RAW_LOG_ERROR(__VA_ARGS__); \
82         break; \
83       case 3: \
84         RAW_LOG_FATAL(__VA_ARGS__); \
85         break; \
86       default: \
87         break; \
88     } \
89   } while (0)
90
91 // The following STRIP_LOG testing is performed in the header file so that it's
92 // possible to completely compile out the logging code and the log messages.
93 #if STRIP_LOG == 0
94 #define RAW_VLOG(verboselevel, ...) \
95   do { \
96     if (VLOG_IS_ON(verboselevel)) { \
97       RAW_LOG_INFO(__VA_ARGS__); \
98     } \
99   } while (0)
100 #else
101 #define RAW_VLOG(verboselevel, ...) RawLogStub__(0, __VA_ARGS__)
102 #endif // STRIP_LOG == 0
103
104 #if STRIP_LOG == 0
105 #define RAW_LOG_INFO(...) google::RawLog__(google::INFO, \
106                                    __FILE__, __LINE__, __VA_ARGS__)
107 #else
108 #define RAW_LOG_INFO(...) google::RawLogStub__(0, __VA_ARGS__)
109 #endif // STRIP_LOG == 0
110
111 #if STRIP_LOG <= 1
112 #define RAW_LOG_WARNING(...) google::RawLog__(google::WARNING,   \
113                                       __FILE__, __LINE__, __VA_ARGS__)
114 #else
115 #define RAW_LOG_WARNING(...) google::RawLogStub__(0, __VA_ARGS__)
116 #endif // STRIP_LOG <= 1
117
118 #if STRIP_LOG <= 2
119 #define RAW_LOG_ERROR(...) google::RawLog__(google::ERROR,       \
120                                     __FILE__, __LINE__, __VA_ARGS__)
121 #else
122 #define RAW_LOG_ERROR(...) google::RawLogStub__(0, __VA_ARGS__)
123 #endif // STRIP_LOG <= 2
124
125 #if STRIP_LOG <= 3
126 #define RAW_LOG_FATAL(...) google::RawLog__(google::FATAL,       \
127                                     __FILE__, __LINE__, __VA_ARGS__)
128 #else
129 #define RAW_LOG_FATAL(...) \
130   do { \
131     google::RawLogStub__(0, __VA_ARGS__);        \
132     exit(1); \
133   } while (0)
134 #endif // STRIP_LOG <= 3
135
136 // Similar to CHECK(condition) << message,
137 // but for low-level modules: we use only RAW_LOG that does not allocate memory.
138 // We do not want to provide args list here to encourage this usage:
139 //   if (!cond)  RAW_LOG(FATAL, "foo ...", hard_to_compute_args);
140 // so that the args are not computed when not needed.
141 #define RAW_CHECK(condition, message)                                   \
142   do {                                                                  \
143     if (!(condition)) {                                                 \
144       RAW_LOG(FATAL, "Check %s failed: %s", #condition, message);       \
145     }                                                                   \
146   } while (0)
147
148 // Debug versions of RAW_LOG and RAW_CHECK
149 #ifndef NDEBUG
150
151 #define RAW_DLOG(severity, ...) RAW_LOG(severity, __VA_ARGS__)
152 #define RAW_DCHECK(condition, message) RAW_CHECK(condition, message)
153
154 #else  // NDEBUG
155
156 #define RAW_DLOG(severity, ...)                                 \
157   while (false)                                                 \
158     RAW_LOG(severity, __VA_ARGS__)
159 #define RAW_DCHECK(condition, message) \
160   while (false) \
161     RAW_CHECK(condition, message)
162
163 #endif  // NDEBUG
164
165 // Stub log function used to work around for unused variable warnings when
166 // building with STRIP_LOG > 0.
167 static inline void RawLogStub__(int ignored, ...) {
168 }
169
170 // Helper function to implement RAW_LOG and RAW_VLOG
171 // Logs format... at "severity" level, reporting it
172 // as called from file:line.
173 // This does not allocate memory or acquire locks.
174 GOOGLE_GLOG_DLL_DECL void RawLog__(LogSeverity severity,
175                                    const char* file,
176                                    int line,
177                                    const char* format, ...)
178    ;
179
180 // Hack to propagate time information into this module so that
181 // this module does not have to directly call localtime_r(),
182 // which could allocate memory.
183 extern "C" struct ::tm;
184 GOOGLE_GLOG_DLL_DECL void RawLog__SetLastTime(const struct ::tm& t, int usecs);
185
186 }
187
188 #endif  // BASE_RAW_LOGGING_H_