protobuf/src/google/protobuf/stubs/logging.h
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef GOOGLE_PROTOBUF_STUBS_LOGGING_H_
32 #define GOOGLE_PROTOBUF_STUBS_LOGGING_H_
33 
34 #include <google/protobuf/stubs/macros.h>
35 #include <google/protobuf/stubs/port.h>
36 #include <google/protobuf/stubs/status.h>
37 #include <google/protobuf/stubs/stringpiece.h>
38 
39 #include <google/protobuf/port_def.inc>
40 
41 // ===================================================================
42 // emulates google3/base/logging.h
43 
44 namespace google {
45 namespace protobuf {
46 
47 enum LogLevel {
48  LOGLEVEL_INFO, // Informational. This is never actually used by
49  // libprotobuf.
50  LOGLEVEL_WARNING, // Warns about issues that, although not technically a
51  // problem now, could cause problems in the future. For
52  // example, a // warning will be printed when parsing a
53  // message that is near the message size limit.
54  LOGLEVEL_ERROR, // An error occurred which should never happen during
55  // normal use.
56  LOGLEVEL_FATAL, // An error occurred from which the library cannot
57  // recover. This usually indicates a programming error
58  // in the code which calls the library, especially when
59  // compiled in debug mode.
60 
61 #ifdef NDEBUG
63 #else
65 #endif
66 };
67 
68 class uint128;
69 namespace internal {
70 
71 class LogFinisher;
72 
73 class PROTOBUF_EXPORT LogMessage {
74  public:
75  LogMessage(LogLevel level, const char* filename, int line);
76  ~LogMessage();
77 
79  LogMessage& operator<<(const char* value);
84  LogMessage& operator<<(unsigned long value);
85  LogMessage& operator<<(long long value);
86  LogMessage& operator<<(unsigned long long value);
87  LogMessage& operator<<(double value);
88  LogMessage& operator<<(void* value);
89  LogMessage& operator<<(const StringPiece& value);
91  LogMessage& operator<<(const uint128& value);
92 
93  private:
94  friend class LogFinisher;
95  void Finish();
96 
97  LogLevel level_;
98  const char* filename_;
99  int line_;
100  std::string message_;
101 };
102 
103 // Used to make the entire "LOG(BLAH) << etc." expression have a void return
104 // type and print a newline after each message.
105 class PROTOBUF_EXPORT LogFinisher {
106  public:
107  void operator=(LogMessage& other);
108 };
109 
110 template<typename T>
111 bool IsOk(T status) { return status.ok(); }
112 template<>
113 inline bool IsOk(bool status) { return status; }
114 
115 } // namespace internal
116 
117 // Undef everything in case we're being mixed with some other Google library
118 // which already defined them itself. Presumably all Google libraries will
119 // support the same syntax for these so it should not be a big deal if they
120 // end up using our definitions instead.
121 #undef GOOGLE_LOG
122 #undef GOOGLE_LOG_IF
123 
124 #undef GOOGLE_CHECK
125 #undef GOOGLE_CHECK_OK
126 #undef GOOGLE_CHECK_EQ
127 #undef GOOGLE_CHECK_NE
128 #undef GOOGLE_CHECK_LT
129 #undef GOOGLE_CHECK_LE
130 #undef GOOGLE_CHECK_GT
131 #undef GOOGLE_CHECK_GE
132 #undef GOOGLE_CHECK_NOTNULL
133 
134 #undef GOOGLE_DLOG
135 #undef GOOGLE_DCHECK
136 #undef GOOGLE_DCHECK_OK
137 #undef GOOGLE_DCHECK_EQ
138 #undef GOOGLE_DCHECK_NE
139 #undef GOOGLE_DCHECK_LT
140 #undef GOOGLE_DCHECK_LE
141 #undef GOOGLE_DCHECK_GT
142 #undef GOOGLE_DCHECK_GE
143 
144 #define GOOGLE_LOG(LEVEL) \
145  ::google::protobuf::internal::LogFinisher() = \
146  ::google::protobuf::internal::LogMessage( \
147  ::google::protobuf::LOGLEVEL_##LEVEL, __FILE__, __LINE__)
148 #define GOOGLE_LOG_IF(LEVEL, CONDITION) \
149  !(CONDITION) ? (void)0 : GOOGLE_LOG(LEVEL)
150 
151 #define GOOGLE_CHECK(EXPRESSION) \
152  GOOGLE_LOG_IF(FATAL, !(EXPRESSION)) << "CHECK failed: " #EXPRESSION ": "
153 #define GOOGLE_CHECK_OK(A) GOOGLE_CHECK(::google::protobuf::internal::IsOk(A))
154 #define GOOGLE_CHECK_EQ(A, B) GOOGLE_CHECK((A) == (B))
155 #define GOOGLE_CHECK_NE(A, B) GOOGLE_CHECK((A) != (B))
156 #define GOOGLE_CHECK_LT(A, B) GOOGLE_CHECK((A) < (B))
157 #define GOOGLE_CHECK_LE(A, B) GOOGLE_CHECK((A) <= (B))
158 #define GOOGLE_CHECK_GT(A, B) GOOGLE_CHECK((A) > (B))
159 #define GOOGLE_CHECK_GE(A, B) GOOGLE_CHECK((A) >= (B))
160 
161 namespace internal {
162 template<typename T>
163 T* CheckNotNull(const char* /* file */, int /* line */,
164  const char* name, T* val) {
165  if (val == nullptr) {
166  GOOGLE_LOG(FATAL) << name;
167  }
168  return val;
169 }
170 } // namespace internal
171 #define GOOGLE_CHECK_NOTNULL(A) \
172  ::google::protobuf::internal::CheckNotNull( \
173  __FILE__, __LINE__, "'" #A "' must not be nullptr", (A))
174 
175 #ifdef NDEBUG
176 
177 #define GOOGLE_DLOG(LEVEL) GOOGLE_LOG_IF(LEVEL, false)
178 
179 #define GOOGLE_DCHECK(EXPRESSION) while(false) GOOGLE_CHECK(EXPRESSION)
180 #define GOOGLE_DCHECK_OK(E) GOOGLE_DCHECK(::google::protobuf::internal::IsOk(E))
181 #define GOOGLE_DCHECK_EQ(A, B) GOOGLE_DCHECK((A) == (B))
182 #define GOOGLE_DCHECK_NE(A, B) GOOGLE_DCHECK((A) != (B))
183 #define GOOGLE_DCHECK_LT(A, B) GOOGLE_DCHECK((A) < (B))
184 #define GOOGLE_DCHECK_LE(A, B) GOOGLE_DCHECK((A) <= (B))
185 #define GOOGLE_DCHECK_GT(A, B) GOOGLE_DCHECK((A) > (B))
186 #define GOOGLE_DCHECK_GE(A, B) GOOGLE_DCHECK((A) >= (B))
187 
188 #else // NDEBUG
189 
190 #define GOOGLE_DLOG GOOGLE_LOG
191 
192 #define GOOGLE_DCHECK GOOGLE_CHECK
193 #define GOOGLE_DCHECK_OK GOOGLE_CHECK_OK
194 #define GOOGLE_DCHECK_EQ GOOGLE_CHECK_EQ
195 #define GOOGLE_DCHECK_NE GOOGLE_CHECK_NE
196 #define GOOGLE_DCHECK_LT GOOGLE_CHECK_LT
197 #define GOOGLE_DCHECK_LE GOOGLE_CHECK_LE
198 #define GOOGLE_DCHECK_GT GOOGLE_CHECK_GT
199 #define GOOGLE_DCHECK_GE GOOGLE_CHECK_GE
200 
201 #endif // !NDEBUG
202 
203 typedef void LogHandler(LogLevel level, const char* filename, int line,
204  const std::string& message);
205 
206 // The protobuf library sometimes writes warning and error messages to
207 // stderr. These messages are primarily useful for developers, but may
208 // also help end users figure out a problem. If you would prefer that
209 // these messages be sent somewhere other than stderr, call SetLogHandler()
210 // to set your own handler. This returns the old handler. Set the handler
211 // to nullptr to ignore log messages (but see also LogSilencer, below).
212 //
213 // Obviously, SetLogHandler is not thread-safe. You should only call it
214 // at initialization time, and probably not from library code. If you
215 // simply want to suppress log messages temporarily (e.g. because you
216 // have some code that tends to trigger them frequently and you know
217 // the warnings are not important to you), use the LogSilencer class
218 // below.
219 PROTOBUF_EXPORT LogHandler* SetLogHandler(LogHandler* new_func);
220 
221 // Create a LogSilencer if you want to temporarily suppress all log
222 // messages. As long as any LogSilencer objects exist, non-fatal
223 // log messages will be discarded (the current LogHandler will *not*
224 // be called). Constructing a LogSilencer is thread-safe. You may
225 // accidentally suppress log messages occurring in another thread, but
226 // since messages are generally for debugging purposes only, this isn't
227 // a big deal. If you want to intercept log messages, use SetLogHandler().
228 class PROTOBUF_EXPORT LogSilencer {
229  public:
230  LogSilencer();
231  ~LogSilencer();
232 };
233 
234 } // namespace protobuf
235 } // namespace google
236 
237 #include <google/protobuf/port_undef.inc>
238 
239 #endif // GOOGLE_PROTOBUF_STUBS_LOGGING_H_
filename
const char * filename
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:135
google::protobuf::value
const Descriptor::ReservedRange value
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:1954
google::protobuf::LOGLEVEL_FATAL
@ LOGLEVEL_FATAL
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:54
LogMessage
Definition: bloaty/third_party/re2/util/logging.h:57
line_
int line_
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc:1468
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
google::protobuf::LogLevel
LogLevel
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:45
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
status
absl::Status status
Definition: rls.cc:251
setup.name
name
Definition: setup.py:542
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
T
#define T(upbtypeconst, upbtype, ctype, default_value)
google::protobuf.internal::IsOk
bool IsOk(T status)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:113
uint
unsigned int uint
Definition: bloaty/third_party/zlib/examples/gzlog.c:242
google::protobuf::operator<<
std::ostream & operator<<(std::ostream &o, const uint128 &b)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/int128.cc:128
google::protobuf::LOGLEVEL_WARNING
@ LOGLEVEL_WARNING
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:48
FATAL
#define FATAL(msg)
Definition: task.h:88
benchmark::internal::Finish
double Finish(Counter const &c, IterationCount iterations, double cpu_time, double num_threads)
Definition: benchmark/src/counter.cc:20
google::protobuf::LOGLEVEL_DFATAL
@ LOGLEVEL_DFATAL
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:62
google::protobuf::SetLogHandler
LogHandler * SetLogHandler(LogHandler *new_func)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/common.cc:271
grpc::protobuf::util::Status
GRPC_CUSTOM_UTIL_STATUS Status
Definition: include/grpcpp/impl/codegen/config_protobuf.h:93
regen-readme.line
line
Definition: regen-readme.py:30
absl::Status::ok
ABSL_MUST_USE_RESULT bool ok() const
Definition: third_party/abseil-cpp/absl/status/status.h:802
GOOGLE_LOG
#define GOOGLE_LOG(LEVEL)
Definition: protobuf/src/google/protobuf/stubs/logging.h:144
internal
Definition: benchmark/test/output_test_helper.cc:20
google::protobuf::LOGLEVEL_INFO
@ LOGLEVEL_INFO
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:46
client.level
level
Definition: examples/python/async_streaming/client.py:118
google::protobuf::LOGLEVEL_ERROR
@ LOGLEVEL_ERROR
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:52
google::protobuf::LogHandler
void LogHandler(LogLevel level, const char *filename, int line, const std::string &message)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:205
google
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:11
google::protobuf.internal::CheckNotNull
T * CheckNotNull(const char *, int, const char *name, T *val)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:165


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:16