Coverage Report

Created: 2025-08-05 06:45

/src/brpc/src/butil/logging.h
Line
Count
Source (jump to first uncovered line)
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
// Date: 2012-10-08 23:53:50
19
20
// Merged chromium log and streaming log.
21
22
#ifndef BUTIL_LOGGING_H_
23
#define BUTIL_LOGGING_H_
24
25
#include "butil/config.h"   // BRPC_WITH_GLOG
26
27
#include <inttypes.h>
28
#include <string>
29
#include <cstring>
30
#include <sstream>
31
#include "butil/macros.h"    // BAIDU_CONCAT
32
#include "butil/atomicops.h" // Used by LOG_EVERY_N, LOG_FIRST_N etc
33
#include "butil/time.h"      // gettimeofday_us()
34
35
#if BRPC_WITH_GLOG
36
# include <glog/logging.h>
37
# include <glog/raw_logging.h>
38
// define macros that not implemented in glog
39
# ifndef DCHECK_IS_ON   // glog didn't define DCHECK_IS_ON in older version
40
#  if defined(NDEBUG)
41
#    define DCHECK_IS_ON() 0
42
#  else
43
#    define DCHECK_IS_ON() 1
44
#  endif  // NDEBUG
45
# endif // DCHECK_IS_ON
46
# if DCHECK_IS_ON() 
47
#  define DPLOG(...) PLOG(__VA_ARGS__)
48
#  define DPLOG_IF(...) PLOG_IF(__VA_ARGS__)
49
#  define DPCHECK(...) PCHECK(__VA_ARGS__)
50
#  define DVPLOG(...) VLOG(__VA_ARGS__)
51
# else 
52
#  define DPLOG(...) DLOG(__VA_ARGS__)
53
#  define DPLOG_IF(...) DLOG_IF(__VA_ARGS__)
54
#  define DPCHECK(...) DCHECK(__VA_ARGS__)
55
#  define DVPLOG(...) DVLOG(__VA_ARGS__)
56
# endif // DCHECK_IS_ON()
57
58
#ifndef LOG_BACKTRACE_IF
59
#define LOG_BACKTRACE_IF(severity, condition) LOG_IF(severity, condition)
60
#endif // LOG_BACKTRACE_IF
61
62
#ifndef LOG_BACKTRACE_IF_ONCE
63
#define LOG_BACKTRACE_IF_ONCE(severity, condition) LOG_IF_ONCE(severity, condition)
64
#endif // LOG_BACKTRACE_IF_ONCE
65
66
#ifndef LOG_BACKTRACE_FIRST_N
67
#define LOG_BACKTRACE_FIRST_N(severity, N) LOG_FIRST_N(severity, N)
68
#endif // LOG_BACKTRACE_FIRST_N
69
70
#ifndef LOG_BACKTRACE_IF_FIRST_N
71
#define LOG_BACKTRACE_IF_FIRST_N(severity, condition, N) LOG_IF_FIRST_N(severity, condition, N)
72
#endif // LOG_BACKTRACE_IF_FIRST_N
73
74
75
#define LOG_AT(severity, file, line)                                    \
76
    ::google::LogMessage(file, line, ::google::severity).stream()
77
78
#else
79
80
#ifdef BAIDU_INTERNAL
81
// gejun: com_log.h includes ul_def.h, undef conflict macros
82
// FIXME(gejun): We have to include com_log which is assumed to be included
83
// in other modules right now.
84
#include <com_log.h>
85
#undef Uchar
86
#undef Ushort
87
#undef Uint
88
#undef Max
89
#undef Min
90
#undef Exchange
91
#endif // BAIDU_INTERNAL
92
93
#include <inttypes.h>
94
#include <gflags/gflags_declare.h>
95
96
#include "butil/base_export.h"
97
#include "butil/basictypes.h"
98
#include "butil/debug/debugger.h"
99
#include "butil/strings/string_piece.h"
100
#include "butil/build_config.h"
101
#include "butil/synchronization/lock.h"
102
//
103
// Optional message capabilities
104
// -----------------------------
105
// Assertion failed messages and fatal errors are displayed in a dialog box
106
// before the application exits. However, running this UI creates a message
107
// loop, which causes application messages to be processed and potentially
108
// dispatched to existing application windows. Since the application is in a
109
// bad state when this assertion dialog is displayed, these messages may not
110
// get processed and hang the dialog, or the application might go crazy.
111
//
112
// Therefore, it can be beneficial to display the error dialog in a separate
113
// process from the main application. When the logging system needs to display
114
// a fatal error dialog box, it will look for a program called
115
// "DebugMessage.exe" in the same directory as the application executable. It
116
// will run this application with the message as the command line, and will
117
// not include the name of the application as is traditional for easier
118
// parsing.
119
//
120
// The code for DebugMessage.exe is only one line. In WinMain, do:
121
//   MessageBox(NULL, GetCommandLineW(), L"Fatal Error", 0);
122
//
123
// If DebugMessage.exe is not found, the logging code will use a normal
124
// MessageBox, potentially causing the problems discussed above.
125
126
127
// Instructions
128
// ------------
129
//
130
// Make a bunch of macros for logging.  The way to log things is to stream
131
// things to LOG(<a particular severity level>).  E.g.,
132
//
133
//   LOG(INFO) << "Found " << num_cookies << " cookies";
134
//
135
// You can also do conditional logging:
136
//
137
//   LOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
138
//
139
// The CHECK(condition) macro is active in both debug and release builds and
140
// effectively performs a LOG(FATAL) which terminates the process and
141
// generates a crashdump unless a debugger is attached.
142
//
143
// There are also "debug mode" logging macros like the ones above:
144
//
145
//   DLOG(INFO) << "Found cookies";
146
//
147
//   DLOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
148
//
149
// All "debug mode" logging is compiled away to nothing for non-debug mode
150
// compiles.  LOG_IF and development flags also work well together
151
// because the code can be compiled away sometimes.
152
//
153
// We also have
154
//
155
//   LOG_ASSERT(assertion);
156
//   DLOG_ASSERT(assertion);
157
//
158
// which is syntactic sugar for {,D}LOG_IF(FATAL, assert fails) << assertion;
159
//
160
// There are "verbose level" logging macros.  They look like
161
//
162
//   VLOG(1) << "I'm printed when you run the program with --v=1 or more";
163
//   VLOG(2) << "I'm printed when you run the program with --v=2 or more";
164
//
165
// These always log at the INFO log level (when they log at all).
166
// The verbose logging can also be turned on module-by-module.  For instance,
167
//    --vmodule=profile=2,icon_loader=1,browser_*=3,*/chromeos/*=4 --v=0
168
// will cause:
169
//   a. VLOG(2) and lower messages to be printed from profile.{h,cc}
170
//   b. VLOG(1) and lower messages to be printed from icon_loader.{h,cc}
171
//   c. VLOG(3) and lower messages to be printed from files prefixed with
172
//      "browser"
173
//   d. VLOG(4) and lower messages to be printed from files under a
174
//     "chromeos" directory.
175
//   e. VLOG(0) and lower messages to be printed from elsewhere
176
//
177
// The wildcarding functionality shown by (c) supports both '*' (match
178
// 0 or more characters) and '?' (match any single character)
179
// wildcards.  Any pattern containing a forward or backward slash will
180
// be tested against the whole pathname and not just the module.
181
// E.g., "*/foo/bar/*=2" would change the logging level for all code
182
// in source files under a "foo/bar" directory.
183
//
184
// There's also VLOG_IS_ON(n) "verbose level" condition macro. To be used as
185
//
186
//   if (VLOG_IS_ON(2)) {
187
//     // do some logging preparation and logging
188
//     // that can't be accomplished with just VLOG(2) << ...;
189
//   }
190
//
191
// There is also a VLOG_IF "verbose level" condition macro for sample
192
// cases, when some extra computation and preparation for logs is not
193
// needed.
194
//
195
//   VLOG_IF(1, (size > 1024))
196
//      << "I'm printed when size is more than 1024 and when you run the "
197
//         "program with --v=1 or more";
198
//
199
// Lastly, there is:
200
//
201
//   PLOG(ERROR) << "Couldn't do foo";
202
//   DPLOG(ERROR) << "Couldn't do foo";
203
//   PLOG_IF(ERROR, cond) << "Couldn't do foo";
204
//   DPLOG_IF(ERROR, cond) << "Couldn't do foo";
205
//   PCHECK(condition) << "Couldn't do foo";
206
//   DPCHECK(condition) << "Couldn't do foo";
207
//
208
// which append the last system error to the message in string form (taken from
209
// GetLastError() on Windows and errno on POSIX).
210
//
211
// The supported severity levels for macros that allow you to specify one
212
// are (in increasing order of severity) INFO, WARNING, ERROR, and FATAL.
213
//
214
// Very important: logging a message at the FATAL severity level causes
215
// the program to terminate (after the message is logged).
216
//
217
// There is the special severity of DFATAL, which logs FATAL in debug mode,
218
// ERROR in normal mode.
219
220
namespace logging {
221
222
// TODO(avi): do we want to do a unification of character types here?
223
#if defined(OS_WIN)
224
typedef wchar_t LogChar;
225
#else
226
typedef char LogChar;
227
#endif
228
229
// Where to record logging output? A flat file and/or system debug log
230
// via OutputDebugString.
231
enum LoggingDestination {
232
    LOG_TO_NONE             = 0,
233
    LOG_TO_FILE             = 1 << 0,
234
    LOG_TO_SYSTEM_DEBUG_LOG = 1 << 1,
235
236
    LOG_TO_ALL = LOG_TO_FILE | LOG_TO_SYSTEM_DEBUG_LOG,
237
238
    // On Windows, use a file next to the exe; on POSIX platforms, where
239
    // it may not even be possible to locate the executable on disk, use
240
    // stderr.
241
#if defined(OS_WIN)
242
    LOG_DEFAULT = LOG_TO_FILE,
243
#elif defined(OS_POSIX)
244
    LOG_DEFAULT = LOG_TO_SYSTEM_DEBUG_LOG,
245
#endif
246
};
247
248
// Indicates that the log file should be locked when being written to.
249
// Unless there is only one single-threaded process that is logging to
250
// the log file, the file should be locked during writes to make each
251
// log output atomic. Other writers will block.
252
//
253
// All processes writing to the log file must have their locking set for it to
254
// work properly. Defaults to LOCK_LOG_FILE.
255
enum LogLockingState { LOCK_LOG_FILE, DONT_LOCK_LOG_FILE };
256
257
// On startup, should we delete or append to an existing log file (if any)?
258
// Defaults to APPEND_TO_OLD_LOG_FILE.
259
enum OldFileDeletionState { DELETE_OLD_LOG_FILE, APPEND_TO_OLD_LOG_FILE };
260
261
struct BUTIL_EXPORT LoggingSettings {
262
    // The defaults values are:
263
    //
264
    //  logging_dest: LOG_DEFAULT
265
    //  log_file:     NULL
266
    //  lock_log:     LOCK_LOG_FILE
267
    //  delete_old:   APPEND_TO_OLD_LOG_FILE
268
    LoggingSettings();
269
270
    LoggingDestination logging_dest;
271
272
    // The three settings below have an effect only when LOG_TO_FILE is
273
    // set in |logging_dest|.
274
    const LogChar* log_file;
275
    LogLockingState lock_log;
276
    OldFileDeletionState delete_old;
277
};
278
279
// Implementation of the InitLogging() method declared below. 
280
BUTIL_EXPORT bool BaseInitLoggingImpl(const LoggingSettings& settings);
281
282
// Sets the log file name and other global logging state. Calling this function
283
// is recommended, and is normally done at the beginning of application init.
284
// If you don't call it, all the flags will be initialized to their default
285
// values, and there is a race condition that may leak a critical section
286
// object if two threads try to do the first log at the same time.
287
// See the definition of the enums above for descriptions and default values.
288
//
289
// The default log file is initialized to "<process-name>.log" on linux and
290
// "debug.log" otherwise.
291
//
292
// This function may be called a second time to re-direct logging (e.g after
293
// loging in to a user partition), however it should never be called more than
294
// twice.
295
0
inline bool InitLogging(const LoggingSettings& settings) {
296
0
    return BaseInitLoggingImpl(settings);
297
0
}
298
299
// Sets the log level. Anything at or above this level will be written to the
300
// log file/displayed to the user (if applicable). Anything below this level
301
// will be silently ignored. The log level defaults to 0 (everything is logged
302
// up to level INFO) if this function is not called.
303
BUTIL_EXPORT void SetMinLogLevel(int level);
304
305
// Gets the current log level.
306
BUTIL_EXPORT int GetMinLogLevel();
307
308
// Sets whether or not you'd like to see fatal debug messages popped up in
309
// a dialog box or not.
310
// Dialogs are not shown by default.
311
BUTIL_EXPORT void SetShowErrorDialogs(bool enable_dialogs);
312
313
// Sets the Log Assert Handler that will be used to notify of check failures.
314
// The default handler shows a dialog box and then terminate the process,
315
// however clients can use this function to override with their own handling
316
// (e.g. a silent one for Unit Tests)
317
typedef void (*LogAssertHandler)(const std::string& str);
318
BUTIL_EXPORT void SetLogAssertHandler(LogAssertHandler handler);
319
320
class LogSink {
321
public:
322
1
    LogSink() {}
323
0
    virtual ~LogSink() {}
324
    // Called when a log is ready to be written out.
325
    // Returns true to stop further processing.
326
    virtual bool OnLogMessage(int severity, const char* file, int line,
327
                              const butil::StringPiece& log_content) = 0;
328
    virtual bool OnLogMessage(int severity, const char* file,
329
                              int line, const char* /*func*/,
330
0
                              const butil::StringPiece& log_content) {
331
0
        return OnLogMessage(severity, file, line, log_content);
332
0
    }
333
private:
334
    DISALLOW_COPY_AND_ASSIGN(LogSink);
335
};
336
337
// Sets the LogSink that gets passed every log message before
338
// it's sent to default log destinations.
339
// This function is thread-safe and waits until current LogSink is not used
340
// anymore.
341
// Returns previous sink.
342
BUTIL_EXPORT LogSink* SetLogSink(LogSink* sink);
343
344
// Print |content| with other info into |os|.
345
void PrintLog(std::ostream& os,
346
              int severity, const char* file, int line,
347
              const butil::StringPiece& content);
348
349
void PrintLog(std::ostream& os,
350
              int severity, const char* file, int line,
351
              const char* func, const butil::StringPiece& content);
352
353
// The LogSink mainly for unit-testing. Logs will be appended to it.
354
class StringSink : public LogSink, public std::string {
355
public:
356
    bool OnLogMessage(int severity, const char* file, int line,
357
                      const butil::StringPiece& log_content) override;
358
359
    bool OnLogMessage(int severity, const char* file,
360
                      int line, const char* func,
361
                      const butil::StringPiece& log_content) override;
362
private:
363
    butil::Lock _lock;
364
};
365
366
typedef int LogSeverity;
367
const LogSeverity BLOG_VERBOSE = -1;  // This is level 1 verbosity
368
// Note: the log severities are used to index into the array of names,
369
// see log_severity_names.
370
const LogSeverity BLOG_INFO = 0;
371
const LogSeverity BLOG_NOTICE = 1;
372
const LogSeverity BLOG_WARNING = 2;
373
const LogSeverity BLOG_ERROR = 3;
374
const LogSeverity BLOG_FATAL = 4;
375
const int LOG_NUM_SEVERITIES = 5;
376
377
// COMBLOG_TRACE is just INFO
378
const LogSeverity BLOG_TRACE = BLOG_INFO;
379
380
// COMBLOG_DEBUG equals INFO in debug mode and verbose in normal mode.
381
#ifndef NDEBUG
382
const LogSeverity BLOG_DEBUG = BLOG_INFO;
383
#else
384
const LogSeverity BLOG_DEBUG = BLOG_VERBOSE;
385
#endif
386
387
// BLOG_DFATAL is BLOG_FATAL in debug mode, ERROR in normal mode
388
#ifndef NDEBUG
389
const LogSeverity BLOG_DFATAL = BLOG_FATAL;
390
#else
391
const LogSeverity BLOG_DFATAL = BLOG_ERROR;
392
#endif
393
394
// A few definitions of macros that don't generate much code. These are used
395
// by LOG() and LOG_IF, etc. Since these are used all over our code, it's
396
// better to have compact code for these operations.
397
#define BAIDU_COMPACT_LOG_EX(severity, ClassName, ...)  \
398
    ::logging::ClassName(__FILE__, __LINE__,  __func__, \
399
    ::logging::BLOG_##severity, ##__VA_ARGS__)
400
401
#define BAIDU_COMPACK_LOG(severity)             \
402
    BAIDU_COMPACT_LOG_EX(severity, LogMessage)
403
404
#if defined(OS_WIN)
405
// wingdi.h defines ERROR to be 0. When we call LOG(ERROR), it gets
406
// substituted with 0, and it expands to BAIDU_COMPACK_LOG(0). To allow us
407
// to keep using this syntax, we define this macro to do the same thing
408
// as BAIDU_COMPACK_LOG(ERROR), and also define ERROR the same way that
409
// the Windows SDK does for consistency.
410
#undef ERROR
411
#define ERROR 0
412
// Needed for LOG_IS_ON(ERROR).
413
const LogSeverity BLOG_0 = BLOG_ERROR;
414
#endif
415
416
// As special cases, we can assume that LOG_IS_ON(FATAL) always holds. Also,
417
// LOG_IS_ON(DFATAL) always holds in debug mode. In particular, CHECK()s will
418
// always fire if they fail.
419
#define LOG_IS_ON(severity)                                     \
420
    (::logging::BLOG_##severity >= ::logging::GetMinLogLevel())
421
422
#if defined(__GNUC__)
423
// We emit an anonymous static int* variable at every VLOG_IS_ON(n) site.
424
// (Normally) the first time every VLOG_IS_ON(n) site is hit,
425
// we determine what variable will dynamically control logging at this site:
426
// it's either FLAGS_verbose or an appropriate internal variable
427
// matching the current source file that represents results of
428
// parsing of --vmodule flag and/or SetVLOGLevel calls.
429
# define BAIDU_VLOG_IS_ON(verbose_level, filepath)                      \
430
0
    ({ static const int* vlocal = &::logging::VLOG_UNINITIALIZED;       \
431
0
        const int saved_verbose_level = (verbose_level);                \
432
0
        (saved_verbose_level >= 0)/*VLOG(-1) is forbidden*/ &&          \
433
0
            (*vlocal >= saved_verbose_level) &&                         \
434
0
            ((vlocal != &::logging::VLOG_UNINITIALIZED) ||              \
435
0
             (::logging::add_vlog_site(&vlocal, filepath, __LINE__,     \
436
0
                                       saved_verbose_level))); })
437
#else
438
// GNU extensions not available, so we do not support --vmodule.
439
// Dynamic value of FLAGS_verbose always controls the logging level.
440
# define BAIDU_VLOG_IS_ON(verbose_level, filepath)      \
441
    (::logging::FLAGS_v >= (verbose_level))
442
#endif
443
444
0
#define VLOG_IS_ON(verbose_level) BAIDU_VLOG_IS_ON(verbose_level, __FILE__)
445
446
DECLARE_int32(v);
447
448
extern const int VLOG_UNINITIALIZED;
449
450
// Called to initialize a VLOG callsite.
451
bool add_vlog_site(const int** v, const LogChar* filename,
452
                   int line_no, int required_v);
453
454
class VLogSitePrinter {
455
public:
456
    struct Site {
457
        int current_verbose_level;
458
        int required_verbose_level;
459
        int line_no;
460
        std::string full_module;
461
    };
462
463
    virtual void print(const Site& site) = 0;
464
0
    virtual ~VLogSitePrinter() = default;
465
};
466
467
void print_vlog_sites(VLogSitePrinter*);
468
469
// Helper macro which avoids evaluating the arguments to a stream if
470
// the condition doesn't hold.
471
#define BAIDU_LAZY_STREAM(stream, condition)                            \
472
6.96k
    !(condition) ? (void) 0 : ::logging::LogMessageVoidify() & (stream)
473
474
// We use the preprocessor's merging operator, "##", so that, e.g.,
475
// LOG(INFO) becomes the token BAIDU_COMPACK_LOG(INFO).  There's some funny
476
// subtle difference between ostream member streaming functions (e.g.,
477
// ostream::operator<<(int) and ostream non-member streaming functions
478
// (e.g., ::operator<<(ostream&, string&): it turns out that it's
479
// impossible to stream something like a string directly to an unnamed
480
// ostream. We employ a neat hack by calling the stream() member
481
// function of LogMessage which seems to avoid the problem.
482
#define LOG_STREAM(severity) BAIDU_COMPACK_LOG(severity).stream()
483
484
#define LOG(severity)                                                   \
485
5.34k
    BAIDU_LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity))
486
#define LOG_IF(severity, condition)                                     \
487
0
    BAIDU_LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity) && (condition))
488
#ifndef LOG_BACKTRACE_IF
489
#define LOG_BACKTRACE_IF(severity, condition)                               \
490
    BAIDU_LAZY_STREAM(LOG_STREAM(severity).SetBacktrace(), LOG_IS_ON(severity) && (condition))
491
#endif // LOG_BACKTRACE_IF
492
493
// FIXME(gejun): Should always crash.
494
#define LOG_ASSERT(condition)                                           \
495
    LOG_IF(FATAL, !(condition)) << "Assert failed: " #condition ". "
496
497
#define SYSLOG(severity) LOG(severity)
498
#define SYSLOG_IF(severity, condition) LOG_IF(severity, condition)
499
#define SYSLOG_EVERY_N(severity, N) LOG_EVERY_N(severity, N)
500
#define SYSLOG_IF_EVERY_N(severity, condition, N) LOG_IF_EVERY_N(severity, condition, N)
501
#define SYSLOG_FIRST_N(severity, N) LOG_FIRST_N(severity, N)
502
#define SYSLOG_IF_FIRST_N(severity, condition, N) LOG_IF_FIRST_N(severity, condition, N)
503
#define SYSLOG_ONCE(severity) LOG_FIRST_N(severity, 1)
504
#define SYSLOG_IF_ONCE(severity, condition) LOG_IF_FIRST_N(severity, condition, 1)
505
#define SYSLOG_EVERY_SECOND(severity) LOG_EVERY_SECOND(severity)
506
#define SYSLOG_IF_EVERY_SECOND(severity, condition) LOG_IF_EVERY_SECOND(severity, condition)
507
508
#define SYSLOG_ASSERT(condition)                                        \
509
    SYSLOG_IF(FATAL, !(condition)) << "Assert failed: " #condition ". "
510
511
// file/line can be specified at running-time. This is useful for printing
512
// logs with known file/line inside a LogSink or LogMessageHandler
513
#define LOG_AT_SELECTOR(_1, _2, _3, _4, NAME, ...) NAME
514
515
#define LOG_AT_STREAM1(severity, file, line)                                 \
516
    ::logging::LogMessage(file, line, ::logging::BLOG_##severity).stream()
517
#define LOG_AT_STREAM2(severity, file, line, func)                           \
518
    ::logging::LogMessage(file, line, func, ::logging::BLOG_##severity).stream()
519
#define LOG_AT_STREAM(...) LOG_AT_SELECTOR(__VA_ARGS__, LOG_AT_STREAM2, LOG_AT_STREAM1)(__VA_ARGS__)
520
521
#define LOG_AT1(severity, file, line)                                        \
522
    BAIDU_LAZY_STREAM(LOG_AT_STREAM(severity, file, line), LOG_IS_ON(severity))
523
#define LOG_AT2(severity, file, line, func)                                   \
524
    BAIDU_LAZY_STREAM(LOG_AT_STREAM(severity, file, line, func), LOG_IS_ON(severity))
525
#define LOG_AT(...) LOG_AT_SELECTOR(__VA_ARGS__, LOG_AT2, LOG_AT1)(__VA_ARGS__)
526
527
528
// The VLOG macros log with negative verbosities.
529
#define VLOG_STREAM(verbose_level)                                      \
530
    ::logging::LogMessage(__FILE__, __LINE__, __func__, -(verbose_level)).stream()
531
532
#define VLOG(verbose_level)                                             \
533
1.61k
    BAIDU_LAZY_STREAM(VLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level))
534
#define VLOG_IF(verbose_level, condition)                       \
535
0
    BAIDU_LAZY_STREAM(VLOG_STREAM(verbose_level),               \
536
0
                      VLOG_IS_ON(verbose_level) && (condition))
537
538
#define VLOG_EVERY_N(verbose_level, N)                                  \
539
    BAIDU_LOG_IF_EVERY_N_IMPL(VLOG_IF, verbose_level, true, N)
540
#define VLOG_IF_EVERY_N(verbose_level, condition, N)                    \
541
    BAIDU_LOG_IF_EVERY_N_IMPL(VLOG_IF, verbose_level, condition, N)
542
543
#define VLOG_FIRST_N(verbose_level, N)                                  \
544
    BAIDU_LOG_IF_FIRST_N_IMPL(VLOG_IF, verbose_level, true, N)
545
#define VLOG_IF_FIRST_N(verbose_level, condition, N)                    \
546
    BAIDU_LOG_IF_FIRST_N_IMPL(VLOG_IF, verbose_level, condition, N)
547
548
#define VLOG_ONCE(verbose_level) VLOG_FIRST_N(verbose_level, 1)
549
#define VLOG_IF_ONCE(verbose_level, condition) VLOG_IF_FIRST_N(verbose_level, condition, 1)
550
551
#define VLOG_EVERY_SECOND(verbose_level)                        \
552
    BAIDU_LOG_IF_EVERY_SECOND_IMPL(VLOG_IF, verbose_level, true)
553
#define VLOG_IF_EVERY_SECOND(verbose_level, condition)                  \
554
    BAIDU_LOG_IF_EVERY_SECOND_IMPL(VLOG_IF, verbose_level, condition)
555
556
#if defined (OS_WIN)
557
#define VPLOG_STREAM(verbose_level)                                     \
558
     ::logging::Win32ErrorLogMessage(__FILE__, __LINE__, __func__, -verbose_level, \
559
                                     ::logging::GetLastSystemErrorCode()).stream()
560
#elif defined(OS_POSIX)
561
#define VPLOG_STREAM(verbose_level)                                     \
562
    ::logging::ErrnoLogMessage(__FILE__, __LINE__, __func__, -verbose_level,      \
563
                               ::logging::GetLastSystemErrorCode()).stream()
564
#endif
565
566
#define VPLOG(verbose_level)                                            \
567
    BAIDU_LAZY_STREAM(VPLOG_STREAM(verbose_level), VLOG_IS_ON(verbose_level))
568
569
#define VPLOG_IF(verbose_level, condition)                      \
570
0
    BAIDU_LAZY_STREAM(VPLOG_STREAM(verbose_level),              \
571
0
                      VLOG_IS_ON(verbose_level) && (condition))
572
573
#if defined(OS_WIN)
574
#define PLOG_STREAM(severity)                                           \
575
    BAIDU_COMPACT_LOG_EX(severity, Win32ErrorLogMessage,                \
576
                         ::logging::GetLastSystemErrorCode()).stream()
577
#elif defined(OS_POSIX)
578
#define PLOG_STREAM(severity)                                           \
579
    BAIDU_COMPACT_LOG_EX(severity, ErrnoLogMessage,                     \
580
                         ::logging::GetLastSystemErrorCode()).stream()
581
#endif
582
583
#define PLOG(severity)                                                  \
584
0
    BAIDU_LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity))
585
#define PLOG_IF(severity, condition)                                    \
586
0
    BAIDU_LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity) && (condition))
587
588
// The actual stream used isn't important.
589
#define BAIDU_EAT_STREAM_PARAMS                                           \
590
    true ? (void) 0 : ::logging::LogMessageVoidify() & LOG_STREAM(FATAL)
591
592
// CHECK dies with a fatal error if condition is not true.  It is *not*
593
// controlled by NDEBUG, so the check will be executed regardless of
594
// compilation mode.
595
//
596
// We make sure CHECK et al. always evaluates their arguments, as
597
// doing CHECK(FunctionWithSideEffect()) is a common idiom.
598
599
#if defined(OFFICIAL_BUILD) && defined(NDEBUG)
600
601
// Make all CHECK functions discard their log strings to reduce code
602
// bloat for official release builds.
603
604
// TODO(akalin): This would be more valuable if there were some way to
605
// remove BreakDebugger() from the backtrace, perhaps by turning it
606
// into a macro (like __debugbreak() on Windows).
607
#define CHECK(condition)                                                \
608
    !(condition) ? ::butil::debug::BreakDebugger() : BAIDU_EAT_STREAM_PARAMS
609
610
#define PCHECK(condition) CHECK(condition)
611
612
#define BAIDU_CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2))
613
614
#else
615
616
#define CHECK(condition)                                        \
617
0
    BAIDU_LAZY_STREAM(LOG_STREAM(FATAL).SetCheck(), !(condition))     \
618
0
    << "Check failed: " #condition ". "
619
620
#define PCHECK(condition)                                       \
621
0
    BAIDU_LAZY_STREAM(PLOG_STREAM(FATAL).SetCheck(), !(condition))    \
622
0
    << "Check failed: " #condition ". "
623
624
// Helper macro for binary operators.
625
// Don't use this macro directly in your code, use CHECK_EQ et al below.
626
//
627
// TODO(akalin): Rewrite this so that constructs like if (...)
628
// CHECK_EQ(...) else { ... } work properly.
629
#define BAIDU_CHECK_OP(name, op, val1, val2)                                  \
630
1
    if (std::string* _result =                                          \
631
1
        ::logging::Check##name##Impl((val1), (val2),                    \
632
1
                                     #val1 " " #op " " #val2))          \
633
1
        ::logging::LogMessage(__FILE__, __LINE__, __func__, _result).stream().SetCheck()
634
635
#endif
636
637
// Build the error message string.  This is separate from the "Impl"
638
// function template because it is not performance critical and so can
639
// be out of line, while the "Impl" code should be inline.  Caller
640
// takes ownership of the returned string.
641
template<class t1, class t2>
642
0
std::string* MakeCheckOpString(const t1& v1, const t2& v2, const char* names) {
643
0
    std::ostringstream ss;
644
0
    ss << names << " (" << v1 << " vs " << v2 << "). ";
645
0
    std::string* msg = new std::string(ss.str());
646
0
    return msg;
647
0
}
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<unsigned short, unsigned int>(unsigned short const&, unsigned int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<unsigned long, unsigned short>(unsigned long const&, unsigned short const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<unsigned short, unsigned long>(unsigned short const&, unsigned long const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<butil::IOBuf::Block*, butil::IOBuf::Block*>(butil::IOBuf::Block* const&, butil::IOBuf::Block* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<butil::MPSCQueueNode<butil::IOBufSample*>*, butil::MPSCQueueNode<butil::IOBufSample*>*>(butil::MPSCQueueNode<butil::IOBufSample*>* const&, butil::MPSCQueueNode<butil::IOBufSample*>* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<bthread::TaskGroup*, bthread::TaskGroup*>(bthread::TaskGroup* const&, bthread::TaskGroup* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<bthread::ContextualStack*, bthread::ContextualStack*>(bthread::ContextualStack* const&, bthread::ContextualStack* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<unsigned int, unsigned int>(unsigned int const&, unsigned int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::Socket::WriteRequest*, brpc::Socket::WriteRequest*>(brpc::Socket::WriteRequest* const&, brpc::Socket::WriteRequest* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<butil::fd_guard, int>(butil::fd_guard const&, int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::SSLState, brpc::SSLState>(brpc::SSLState const&, brpc::SSLState const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<int, bthread::TaskNode::TaskStatus>(int const&, bthread::TaskNode::TaskStatus const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<bthread::TaskNode*, bthread::TaskNode*>(bthread::TaskNode* const&, bthread::TaskNode* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<char, int>(char const&, int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<long, int>(long const&, int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<int, int>(int const&, int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<unsigned long, unsigned long>(unsigned long const&, unsigned long const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<unsigned long, unsigned int>(unsigned long const&, unsigned int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<unsigned int, unsigned long>(unsigned int const&, unsigned long const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<void volatile*, void volatile*>(void volatile* const&, void volatile* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<int, long>(int const&, long const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::Serializer const*, brpc::Serializer*>(brpc::Serializer const* const&, brpc::Serializer* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::Deserializer const*, brpc::Deserializer*>(brpc::Deserializer const* const&, brpc::Deserializer* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<google::protobuf::Message const*, brpc::NsheadMessage*>(google::protobuf::Message const* const&, brpc::NsheadMessage* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::NsheadMessage const*, brpc::NsheadMessage*>(brpc::NsheadMessage const* const&, brpc::NsheadMessage* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::policy::H2StreamContext*, brpc::policy::H2StreamContext*>(brpc::policy::H2StreamContext* const&, brpc::policy::H2StreamContext* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::Controller*, brpc::Controller*>(brpc::Controller* const&, brpc::Controller* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::policy::HttpContext*, brpc::Destroyable*>(brpc::policy::HttpContext* const&, brpc::Destroyable* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::RedisRequest const*, brpc::RedisRequest*>(brpc::RedisRequest const* const&, brpc::RedisRequest* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::RedisResponse const*, brpc::RedisResponse*>(brpc::RedisResponse const* const&, brpc::RedisResponse* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::SerializedRequest const*, brpc::SerializedRequest*>(brpc::SerializedRequest const* const&, brpc::SerializedRequest* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::SerializedResponse const*, brpc::SerializedResponse*>(brpc::SerializedResponse const* const&, brpc::SerializedResponse* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<butil::AtExitManager*, butil::AtExitManager*>(butil::AtExitManager* const&, butil::AtExitManager* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<long, long>(long const&, long const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<bthread_id_t, bthread_id_t>(bthread_id_t const&, bthread_id_t const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<butil::EndPoint, butil::EndPoint>(butil::EndPoint const&, butil::EndPoint const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<int, brpc::HuffmanTree::ConstValue>(int const&, brpc::HuffmanTree::ConstValue const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::HuffmanTree::ConstValue, int>(brpc::HuffmanTree::ConstValue const&, int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::HuffmanTree::ConstValue, unsigned short>(brpc::HuffmanTree::ConstValue const&, unsigned short const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::EspMessage const*, brpc::EspMessage*>(brpc::EspMessage const* const&, brpc::EspMessage* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::MemcacheRequest const*, brpc::MemcacheRequest*>(brpc::MemcacheRequest const* const&, brpc::MemcacheRequest* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::MemcacheResponse const*, brpc::MemcacheResponse*>(brpc::MemcacheResponse const* const&, brpc::MemcacheResponse* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::MakeCheckOpString<brpc::ChannelOwnership, brpc::ChannelOwnership>(brpc::ChannelOwnership const&, brpc::ChannelOwnership const&, char const*)
648
649
// MSVC doesn't like complex extern templates and DLLs.
650
#if !defined(COMPILER_MSVC)
651
// Commonly used instantiations of MakeCheckOpString<>. Explicitly instantiated
652
// in logging.cc.
653
extern template BUTIL_EXPORT std::string* MakeCheckOpString<int, int>(
654
    const int&, const int&, const char* names);
655
extern template BUTIL_EXPORT
656
std::string* MakeCheckOpString<unsigned long, unsigned long>(
657
    const unsigned long&, const unsigned long&, const char* names);
658
extern template BUTIL_EXPORT
659
std::string* MakeCheckOpString<unsigned long, unsigned int>(
660
    const unsigned long&, const unsigned int&, const char* names);
661
extern template BUTIL_EXPORT
662
std::string* MakeCheckOpString<unsigned int, unsigned long>(
663
    const unsigned int&, const unsigned long&, const char* names);
664
extern template BUTIL_EXPORT
665
std::string* MakeCheckOpString<std::string, std::string>(
666
    const std::string&, const std::string&, const char* name);
667
#endif
668
669
// Helper functions for BAIDU_CHECK_OP macro.
670
// The (int, int) specialization works around the issue that the compiler
671
// will not instantiate the template version of the function on values of
672
// unnamed enum type - see comment below.
673
#define BAIDU_DEFINE_CHECK_OP_IMPL(name, op)                            \
674
    template <class t1, class t2>                                       \
675
    inline std::string* Check##name##Impl(const t1& v1, const t2& v2,   \
676
0
                                          const char* names) {          \
677
0
        if (v1 op v2) return NULL;                                      \
678
0
        else return MakeCheckOpString(v1, v2, names);                   \
679
0
    }                                                                   \
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<unsigned short, unsigned int>(unsigned short const&, unsigned int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckLEImpl<unsigned long, unsigned short>(unsigned long const&, unsigned short const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<unsigned short, unsigned long>(unsigned short const&, unsigned long const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<butil::IOBuf::Block*, butil::IOBuf::Block*>(butil::IOBuf::Block* const&, butil::IOBuf::Block* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckNEImpl<butil::MPSCQueueNode<butil::IOBufSample*>*, butil::MPSCQueueNode<butil::IOBufSample*>*>(butil::MPSCQueueNode<butil::IOBufSample*>* const&, butil::MPSCQueueNode<butil::IOBufSample*>* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<bthread::TaskGroup*, bthread::TaskGroup*>(bthread::TaskGroup* const&, bthread::TaskGroup* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<bthread::ContextualStack*, bthread::ContextualStack*>(bthread::ContextualStack* const&, bthread::ContextualStack* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<unsigned int, unsigned int>(unsigned int const&, unsigned int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckLTImpl<unsigned long, unsigned long>(unsigned long const&, unsigned long const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckNEImpl<brpc::Socket::WriteRequest*, brpc::Socket::WriteRequest*>(brpc::Socket::WriteRequest* const&, brpc::Socket::WriteRequest* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckGEImpl<butil::fd_guard, int>(butil::fd_guard const&, int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<brpc::Socket::WriteRequest*, brpc::Socket::WriteRequest*>(brpc::Socket::WriteRequest* const&, brpc::Socket::WriteRequest* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<brpc::SSLState, brpc::SSLState>(brpc::SSLState const&, brpc::SSLState const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckNEImpl<int, bthread::TaskNode::TaskStatus>(int const&, bthread::TaskNode::TaskStatus const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckNEImpl<bthread::TaskNode*, bthread::TaskNode*>(bthread::TaskNode* const&, bthread::TaskNode* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<char, int>(char const&, int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<unsigned long, unsigned long>(unsigned long const&, unsigned long const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckGEImpl<long, int>(long const&, int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckGEImpl<unsigned long, unsigned long>(unsigned long const&, unsigned long const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<unsigned long, unsigned int>(unsigned long const&, unsigned int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckLEImpl<unsigned long, unsigned int>(unsigned long const&, unsigned int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<unsigned int, unsigned long>(unsigned int const&, unsigned long const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckLTImpl<long, int>(long const&, int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<unsigned long, unsigned short>(unsigned long const&, unsigned short const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckNEImpl<void volatile*, void volatile*>(void volatile* const&, void volatile* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<bthread::TaskNode*, bthread::TaskNode*>(bthread::TaskNode* const&, bthread::TaskNode* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<int, long>(int const&, long const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckNEImpl<brpc::Serializer const*, brpc::Serializer*>(brpc::Serializer const* const&, brpc::Serializer* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckNEImpl<brpc::Deserializer const*, brpc::Deserializer*>(brpc::Deserializer const* const&, brpc::Deserializer* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckNEImpl<google::protobuf::Message const*, brpc::NsheadMessage*>(google::protobuf::Message const* const&, brpc::NsheadMessage* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckNEImpl<brpc::NsheadMessage const*, brpc::NsheadMessage*>(brpc::NsheadMessage const* const&, brpc::NsheadMessage* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<brpc::policy::H2StreamContext*, brpc::policy::H2StreamContext*>(brpc::policy::H2StreamContext* const&, brpc::policy::H2StreamContext* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<brpc::Controller*, brpc::Controller*>(brpc::Controller* const&, brpc::Controller* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<brpc::policy::HttpContext*, brpc::Destroyable*>(brpc::policy::HttpContext* const&, brpc::Destroyable* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckLEImpl<unsigned long, unsigned long>(unsigned long const&, unsigned long const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckNEImpl<brpc::RedisRequest const*, brpc::RedisRequest*>(brpc::RedisRequest const* const&, brpc::RedisRequest* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckNEImpl<brpc::RedisResponse const*, brpc::RedisResponse*>(brpc::RedisResponse const* const&, brpc::RedisResponse* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckNEImpl<unsigned int, unsigned int>(unsigned int const&, unsigned int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckNEImpl<brpc::SerializedRequest const*, brpc::SerializedRequest*>(brpc::SerializedRequest const* const&, brpc::SerializedRequest* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckNEImpl<brpc::SerializedResponse const*, brpc::SerializedResponse*>(brpc::SerializedResponse const* const&, brpc::SerializedResponse* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<butil::AtExitManager*, butil::AtExitManager*>(butil::AtExitManager* const&, butil::AtExitManager* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckGEImpl<long, long>(long const&, long const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<bthread_id_t, bthread_id_t>(bthread_id_t const&, bthread_id_t const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<butil::EndPoint, butil::EndPoint>(butil::EndPoint const&, butil::EndPoint const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<int, brpc::HuffmanTree::ConstValue>(int const&, brpc::HuffmanTree::ConstValue const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<brpc::HuffmanTree::ConstValue, int>(brpc::HuffmanTree::ConstValue const&, int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<brpc::HuffmanTree::ConstValue, unsigned short>(brpc::HuffmanTree::ConstValue const&, unsigned short const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckLTImpl<unsigned short, unsigned int>(unsigned short const&, unsigned int const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckNEImpl<brpc::EspMessage const*, brpc::EspMessage*>(brpc::EspMessage const* const&, brpc::EspMessage* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckNEImpl<brpc::MemcacheRequest const*, brpc::MemcacheRequest*>(brpc::MemcacheRequest const* const&, brpc::MemcacheRequest* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckNEImpl<brpc::MemcacheResponse const*, brpc::MemcacheResponse*>(brpc::MemcacheResponse const* const&, brpc::MemcacheResponse* const&, char const*)
Unexecuted instantiation: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >* logging::CheckEQImpl<brpc::ChannelOwnership, brpc::ChannelOwnership>(brpc::ChannelOwnership const&, brpc::ChannelOwnership const&, char const*)
680
5.34k
    inline std::string* Check##name##Impl(int v1, int v2, const char* names) { \
681
5.34k
        if (v1 op v2) return NULL;                                      \
682
5.34k
        else return MakeCheckOpString(v1, v2, names);                   \
683
5.34k
    }
logging::CheckEQImpl[abi:cxx11](int, int, char const*)
Line
Count
Source
680
1
    inline std::string* Check##name##Impl(int v1, int v2, const char* names) { \
681
1
        if (v1 op v2) return NULL;                                      \
682
1
        else return MakeCheckOpString(v1, v2, names);                   \
683
1
    }
Unexecuted instantiation: logging::CheckNEImpl[abi:cxx11](int, int, char const*)
Unexecuted instantiation: logging::CheckLEImpl[abi:cxx11](int, int, char const*)
logging::CheckLTImpl[abi:cxx11](int, int, char const*)
Line
Count
Source
680
5.34k
    inline std::string* Check##name##Impl(int v1, int v2, const char* names) { \
681
5.34k
        if (v1 op v2) return NULL;                                      \
682
5.34k
        else return MakeCheckOpString(v1, v2, names);                   \
683
5.34k
    }
Unexecuted instantiation: logging::CheckGEImpl[abi:cxx11](int, int, char const*)
Unexecuted instantiation: logging::CheckGTImpl[abi:cxx11](int, int, char const*)
684
BAIDU_DEFINE_CHECK_OP_IMPL(EQ, ==)
685
BAIDU_DEFINE_CHECK_OP_IMPL(NE, !=)
686
BAIDU_DEFINE_CHECK_OP_IMPL(LE, <=)
687
BAIDU_DEFINE_CHECK_OP_IMPL(LT, < )
688
BAIDU_DEFINE_CHECK_OP_IMPL(GE, >=)
689
BAIDU_DEFINE_CHECK_OP_IMPL(GT, > )
690
#undef BAIDU_DEFINE_CHECK_OP_IMPL
691
692
1
#define CHECK_EQ(val1, val2) BAIDU_CHECK_OP(EQ, ==, val1, val2)
693
0
#define CHECK_NE(val1, val2) BAIDU_CHECK_OP(NE, !=, val1, val2)
694
0
#define CHECK_LE(val1, val2) BAIDU_CHECK_OP(LE, <=, val1, val2)
695
0
#define CHECK_LT(val1, val2) BAIDU_CHECK_OP(LT, < , val1, val2)
696
0
#define CHECK_GE(val1, val2) BAIDU_CHECK_OP(GE, >=, val1, val2)
697
0
#define CHECK_GT(val1, val2) BAIDU_CHECK_OP(GT, > , val1, val2)
698
699
#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
700
#define DCHECK_IS_ON() 0
701
#else
702
5.34k
#define DCHECK_IS_ON() 1
703
#endif
704
705
#define ENABLE_DLOG DCHECK_IS_ON()
706
707
// Definitions for DLOG et al.
708
709
// Need to be this way because `condition' may contain variables that is only
710
// defined in debug mode.
711
#if ENABLE_DLOG
712
#define DLOG_IS_ON(severity) LOG_IS_ON(severity)
713
#define DLOG_IF(severity, condition)                    \
714
    LOG_IF(severity, ENABLE_DLOG && (condition))
715
#define DLOG_ASSERT(condition) LOG_ASSERT(!ENABLE_DLOG || condition)
716
#define DPLOG_IF(severity, condition)                   \
717
    PLOG_IF(severity, ENABLE_DLOG && (condition))
718
#define DVLOG_IF(verbose_level, condition)               \
719
0
    VLOG_IF(verbose_level, ENABLE_DLOG && (condition))
720
#define DVPLOG_IF(verbose_level, condition)      \
721
0
    VPLOG_IF(verbose_level, ENABLE_DLOG && (condition))
722
#else  // ENABLE_DLOG
723
#define DLOG_IS_ON(severity) false
724
#define DLOG_IF(severity, condition) BAIDU_EAT_STREAM_PARAMS
725
#define DLOG_ASSERT(condition) BAIDU_EAT_STREAM_PARAMS
726
#define DPLOG_IF(severity, condition) BAIDU_EAT_STREAM_PARAMS
727
#define DVLOG_IF(verbose_level, condition) BAIDU_EAT_STREAM_PARAMS
728
#define DVPLOG_IF(verbose_level, condition) BAIDU_EAT_STREAM_PARAMS
729
#endif  // ENABLE_DLOG
730
731
#define DLOG(severity)                                          \
732
0
    BAIDU_LAZY_STREAM(LOG_STREAM(severity), DLOG_IS_ON(severity))
733
#define DLOG_EVERY_N(severity, N)                               \
734
    BAIDU_LOG_IF_EVERY_N_IMPL(DLOG_IF, severity, true, N)
735
#define DLOG_IF_EVERY_N(severity, condition, N)                 \
736
    BAIDU_LOG_IF_EVERY_N_IMPL(DLOG_IF, severity, condition, N)
737
#define DLOG_FIRST_N(severity, N)                               \
738
    BAIDU_LOG_IF_FIRST_N_IMPL(DLOG_IF, severity, true, N)
739
#define DLOG_IF_FIRST_N(severity, condition, N)                 \
740
    BAIDU_LOG_IF_FIRST_N_IMPL(DLOG_IF, severity, condition, N)
741
#define DLOG_ONCE(severity) DLOG_FIRST_N(severity, 1)
742
#define DLOG_IF_ONCE(severity, condition) DLOG_IF_FIRST_N(severity, condition, 1)
743
#define DLOG_EVERY_SECOND(severity)                             \
744
    BAIDU_LOG_IF_EVERY_SECOND_IMPL(DLOG_IF, severity, true)
745
#define DLOG_IF_EVERY_SECOND(severity, condition)                       \
746
    BAIDU_LOG_IF_EVERY_SECOND_IMPL(DLOG_IF, severity, condition)
747
748
#define DPLOG(severity)                                         \
749
0
    BAIDU_LAZY_STREAM(PLOG_STREAM(severity), DLOG_IS_ON(severity))
750
#define DPLOG_EVERY_N(severity, N)                               \
751
    BAIDU_LOG_IF_EVERY_N_IMPL(DPLOG_IF, severity, true, N)
752
#define DPLOG_IF_EVERY_N(severity, condition, N)                 \
753
    BAIDU_LOG_IF_EVERY_N_IMPL(DPLOG_IF, severity, condition, N)
754
#define DPLOG_FIRST_N(severity, N)                               \
755
    BAIDU_LOG_IF_FIRST_N_IMPL(DPLOG_IF, severity, true, N)
756
#define DPLOG_IF_FIRST_N(severity, condition, N)                 \
757
    BAIDU_LOG_IF_FIRST_N_IMPL(DPLOG_IF, severity, condition, N)
758
#define DPLOG_ONCE(severity) DPLOG_FIRST_N(severity, 1)
759
#define DPLOG_IF_ONCE(severity, condition) DPLOG_IF_FIRST_N(severity, condition, 1)
760
#define DPLOG_EVERY_SECOND(severity)                             \
761
    BAIDU_LOG_IF_EVERY_SECOND_IMPL(DPLOG_IF, severity, true)
762
#define DPLOG_IF_EVERY_SECOND(severity, condition)                       \
763
    BAIDU_LOG_IF_EVERY_SECOND_IMPL(DPLOG_IF, severity, condition)
764
765
0
#define DVLOG(verbose_level) DVLOG_IF(verbose_level, VLOG_IS_ON(verbose_level))
766
#define DVLOG_EVERY_N(verbose_level, N)                               \
767
    BAIDU_LOG_IF_EVERY_N_IMPL(DVLOG_IF, verbose_level, true, N)
768
#define DVLOG_IF_EVERY_N(verbose_level, condition, N)                 \
769
    BAIDU_LOG_IF_EVERY_N_IMPL(DVLOG_IF, verbose_level, condition, N)
770
#define DVLOG_FIRST_N(verbose_level, N)                               \
771
    BAIDU_LOG_IF_FIRST_N_IMPL(DVLOG_IF, verbose_level, true, N)
772
#define DVLOG_IF_FIRST_N(verbose_level, condition, N)                 \
773
    BAIDU_LOG_IF_FIRST_N_IMPL(DVLOG_IF, verbose_level, condition, N)
774
#define DVLOG_ONCE(verbose_level) DVLOG_FIRST_N(verbose_level, 1)
775
#define DVLOG_IF_ONCE(verbose_level, condition) DVLOG_IF_FIRST_N(verbose_level, condition, 1)
776
#define DVLOG_EVERY_SECOND(verbose_level)                             \
777
    BAIDU_LOG_IF_EVERY_SECOND_IMPL(DVLOG_IF, verbose_level, true)
778
#define DVLOG_IF_EVERY_SECOND(verbose_level, condition)                       \
779
    BAIDU_LOG_IF_EVERY_SECOND_IMPL(DVLOG_IF, verbose_level, condition)
780
781
0
#define DVPLOG(verbose_level) DVPLOG_IF(verbose_level, VLOG_IS_ON(verbose_level))
782
#define DVPLOG_EVERY_N(verbose_level, N)                               \
783
    BAIDU_LOG_IF_EVERY_N_IMPL(DVPLOG_IF, verbose_level, true, N)
784
#define DVPLOG_IF_EVERY_N(verbose_level, condition, N)                 \
785
    BAIDU_LOG_IF_EVERY_N_IMPL(DVPLOG_IF, verbose_level, condition, N)
786
#define DVPLOG_FIRST_N(verbose_level, N)                               \
787
    BAIDU_LOG_IF_FIRST_N_IMPL(DVPLOG_IF, verbose_level, true, N)
788
#define DVPLOG_IF_FIRST_N(verbose_level, condition, N)                 \
789
    BAIDU_LOG_IF_FIRST_N_IMPL(DVPLOG_IF, verbose_level, condition, N)
790
#define DVPLOG_ONCE(verbose_level) DVPLOG_FIRST_N(verbose_level, 1)
791
#define DVPLOG_IF_ONCE(verbose_level, condition) DVPLOG_IF_FIRST_N(verbose_level, condition, 1)
792
#define DVPLOG_EVERY_SECOND(verbose_level)                             \
793
    BAIDU_LOG_IF_EVERY_SECOND_IMPL(DVPLOG_IF, verbose_level, true)
794
#define DVPLOG_IF_EVERY_SECOND(verbose_level, condition)                       \
795
    BAIDU_LOG_IF_EVERY_SECOND_IMPL(DVPLOG_IF, verbose_level, condition)
796
797
// You can assign virtual path to VLOG instead of physical filename.
798
// [public/foo/bar.cpp]
799
// VLOG2("a/b/c", 2) << "being filtered by a/b/c rather than public/foo/bar";
800
#define VLOG2(virtual_path, verbose_level)                              \
801
    BAIDU_LAZY_STREAM(VLOG_STREAM(verbose_level),                       \
802
                      BAIDU_VLOG_IS_ON(verbose_level, virtual_path))
803
804
#define VLOG2_IF(virtual_path, verbose_level, condition)                \
805
    BAIDU_LAZY_STREAM(VLOG_STREAM(verbose_level),                       \
806
                      BAIDU_VLOG_IS_ON(verbose_level, virtual_path) && (condition))
807
808
#define DVLOG2(virtual_path, verbose_level)             \
809
    VLOG2_IF(virtual_path, verbose_level, ENABLE_DLOG)
810
811
#define DVLOG2_IF(virtual_path, verbose_level, condition)               \
812
    VLOG2_IF(virtual_path, verbose_level, ENABLE_DLOG && (condition))
813
814
#define VPLOG2(virtual_path, verbose_level)                             \
815
    BAIDU_LAZY_STREAM(VPLOG_STREAM(verbose_level),                      \
816
                      BAIDU_VLOG_IS_ON(verbose_level, virtual_path))
817
818
#define VPLOG2_IF(virtual_path, verbose_level, condition)               \
819
    BAIDU_LAZY_STREAM(VPLOG_STREAM(verbose_level),                      \
820
                      BAIDU_VLOG_IS_ON(verbose_level, virtual_path) && (condition))
821
822
#define DVPLOG2(virtual_path, verbose_level)                            \
823
    VPLOG2_IF(virtual_path, verbose_level, ENABLE_DLOG)
824
825
#define DVPLOG2_IF(virtual_path, verbose_level, condition)              \
826
    VPLOG2_IF(virtual_path, verbose_level, ENABLE_DLOG && (condition))
827
828
// Definitions for DCHECK et al.
829
830
#if DCHECK_IS_ON()
831
832
const LogSeverity BLOG_DCHECK = BLOG_FATAL;
833
834
#else  // DCHECK_IS_ON
835
836
const LogSeverity BLOG_DCHECK = BLOG_INFO;
837
838
#endif  // DCHECK_IS_ON
839
840
// DCHECK et al. make sure to reference |condition| regardless of
841
// whether DCHECKs are enabled; this is so that we don't get unused
842
// variable warnings if the only use of a variable is in a DCHECK.
843
// This behavior is different from DLOG_IF et al.
844
845
#define DCHECK(condition)                                               \
846
2
    BAIDU_LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON() && !(condition)) \
847
0
    << "Check failed: " #condition ". "
848
849
#define DPCHECK(condition)                                              \
850
    BAIDU_LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON() && !(condition)) \
851
    << "Check failed: " #condition ". "
852
853
// Helper macro for binary operators.
854
// Don't use this macro directly in your code, use DCHECK_EQ et al below.
855
#define BAIDU_DCHECK_OP(name, op, val1, val2)                           \
856
5.34k
    if (DCHECK_IS_ON())                                                   \
857
5.34k
        if (std::string* _result =                                      \
858
5.34k
            ::logging::Check##name##Impl((val1), (val2),                \
859
5.34k
                                         #val1 " " #op " " #val2))      \
860
5.34k
            ::logging::LogMessage(                                      \
861
0
                __FILE__, __LINE__, __func__,                           \
862
0
                ::logging::BLOG_DCHECK,                                 \
863
0
                _result).stream()
864
865
// Equality/Inequality checks - compare two values, and log a
866
// BLOG_DCHECK message including the two values when the result is not
867
// as expected.  The values must have operator<<(ostream, ...)
868
// defined.
869
//
870
// You may append to the error message like so:
871
//   DCHECK_NE(1, 2) << ": The world must be ending!";
872
//
873
// We are very careful to ensure that each argument is evaluated exactly
874
// once, and that anything which is legal to pass as a function argument is
875
// legal here.  In particular, the arguments may be temporary expressions
876
// which will end up being destroyed at the end of the apparent statement,
877
// for example:
878
//   DCHECK_EQ(string("abc")[1], 'b');
879
//
880
// WARNING: These may not compile correctly if one of the arguments is a pointer
881
// and the other is NULL. To work around this, simply static_cast NULL to the
882
// type of the desired pointer.
883
884
0
#define DCHECK_EQ(val1, val2) BAIDU_DCHECK_OP(EQ, ==, val1, val2)
885
0
#define DCHECK_NE(val1, val2) BAIDU_DCHECK_OP(NE, !=, val1, val2)
886
0
#define DCHECK_LE(val1, val2) BAIDU_DCHECK_OP(LE, <=, val1, val2)
887
5.34k
#define DCHECK_LT(val1, val2) BAIDU_DCHECK_OP(LT, < , val1, val2)
888
0
#define DCHECK_GE(val1, val2) BAIDU_DCHECK_OP(GE, >=, val1, val2)
889
#define DCHECK_GT(val1, val2) BAIDU_DCHECK_OP(GT, > , val1, val2)
890
891
#if defined(OS_WIN)
892
typedef unsigned long SystemErrorCode;
893
#elif defined(OS_POSIX)
894
typedef int SystemErrorCode;
895
#endif
896
897
// Alias for ::GetLastError() on Windows and errno on POSIX. Avoids having to
898
// pull in windows.h just for GetLastError() and DWORD.
899
BUTIL_EXPORT SystemErrorCode GetLastSystemErrorCode();
900
BUTIL_EXPORT void SetLastSystemErrorCode(SystemErrorCode err);
901
BUTIL_EXPORT std::string SystemErrorCodeToString(SystemErrorCode error_code);
902
903
// Underlying buffer to store logs. Comparing to using std::ostringstream
904
// directly, this utility exposes more low-level methods so that we avoid
905
// creation of std::string which allocates memory internally.
906
class CharArrayStreamBuf : public std::streambuf {
907
public:
908
2
    explicit CharArrayStreamBuf() : _data(NULL), _size(0) {}
909
    ~CharArrayStreamBuf() override;
910
911
    int overflow(int ch) override;
912
    int sync() override;
913
    void reset();
914
915
private:
916
    char* _data;
917
    size_t _size;
918
};
919
920
// A std::ostream to << objects.
921
// Have to use private inheritance to arrange initialization order.
922
class LogStream : virtual private CharArrayStreamBuf, public std::ostream {
923
friend void DestroyLogStream(LogStream*);
924
public:
925
    LogStream()
926
2
        : std::ostream(this), _file("-"), _line(0), _func("-")
927
2
        , _severity(0) , _noflush(false), _is_check(false), _backtrace(false) {
928
2
    }
929
930
0
    ~LogStream() {
931
0
        _noflush = false;
932
0
        Flush();
933
0
    }
934
935
0
    inline LogStream& operator<<(LogStream& (*m)(LogStream&)) {
936
0
        return m(*this);
937
0
    }
938
939
5.34k
    inline LogStream& operator<<(std::ostream& (*m)(std::ostream&)) {
940
5.34k
        m(*(std::ostream*)this);
941
5.34k
        return *this;
942
5.34k
    }
943
944
10.6k
    template <typename T> inline LogStream& operator<<(T const& t) {
945
10.6k
        *(std::ostream*)this << t;
946
10.6k
        return *this;
947
10.6k
    }
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <butil::BasicStringPiece<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >(butil::BasicStringPiece<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [30]>(char const (&) [30])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <pthread_mutex_t*>(pthread_mutex_t* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [3]>(char const (&) [3])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char const*>(char const* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [33]>(char const (&) [33])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <int volatile*>(int volatile* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [22]>(char const (&) [22])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [24]>(char const (&) [24])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [28]>(char const (&) [28])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [18]>(char const (&) [18])
logging::LogStream& logging::LogStream::operator<< <char [31]>(char const (&) [31])
Line
Count
Source
944
2
    template <typename T> inline LogStream& operator<<(T const& t) {
945
2
        *(std::ostream*)this << t;
946
2
        return *this;
947
2
    }
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [20]>(char const (&) [20])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [35]>(char const (&) [35])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [7]>(char const (&) [7])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <unsigned int>(unsigned int const&)
logging::LogStream& logging::LogStream::operator<< <char [23]>(char const (&) [23])
Line
Count
Source
944
5.34k
    template <typename T> inline LogStream& operator<<(T const& t) {
945
5.34k
        *(std::ostream*)this << t;
946
5.34k
        return *this;
947
5.34k
    }
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <long>(long const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [6]>(char const (&) [6])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [17]>(char const (&) [17])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <void*>(void* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [12]>(char const (&) [12])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <int>(int const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [21]>(char const (&) [21])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [84]>(char const (&) [84])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [62]>(char const (&) [62])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [37]>(char const (&) [37])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [29]>(char const (&) [29])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [32]>(char const (&) [32])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <bthread_mutex_t*>(bthread_mutex_t* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [16]>(char const (&) [16])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <unsigned long>(unsigned long const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [26]>(char const (&) [26])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [13]>(char const (&) [13])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [44]>(char const (&) [44])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [15]>(char const (&) [15])
logging::LogStream& logging::LogStream::operator<< <unsigned short>(unsigned short const&)
Line
Count
Source
944
5.34k
    template <typename T> inline LogStream& operator<<(T const& t) {
945
5.34k
        *(std::ostream*)this << t;
946
5.34k
        return *this;
947
5.34k
    }
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [19]>(char const (&) [19])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [14]>(char const (&) [14])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [8]>(char const (&) [8])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [66]>(char const (&) [66])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [64]>(char const (&) [64])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [27]>(char const (&) [27])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [11]>(char const (&) [11])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [36]>(char const (&) [36])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [5]>(char const (&) [5])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [51]>(char const (&) [51])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [71]>(char const (&) [71])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [9]>(char const (&) [9])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <butil::IOBuf::Block*>(butil::IOBuf::Block* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [10]>(char const (&) [10])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [2]>(char const (&) [2])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [69]>(char const (&) [69])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [25]>(char const (&) [25])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [52]>(char const (&) [52])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [59]>(char const (&) [59])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char*>(char* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [56]>(char const (&) [56])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <butil::File::Error>(butil::File::Error const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <bool>(bool const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [4]>(char const (&) [4])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [39]>(char const (&) [39])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [40]>(char const (&) [40])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <double>(double const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [76]>(char const (&) [76])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <bthread::TaskGroup*>(bthread::TaskGroup* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [50]>(char const (&) [50])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [49]>(char const (&) [49])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [53]>(char const (&) [53])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char>(char const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [41]>(char const (&) [41])
logging::LogStream& logging::LogStream::operator<< <char [42]>(char const (&) [42])
Line
Count
Source
944
2
    template <typename T> inline LogStream& operator<<(T const& t) {
945
2
        *(std::ostream*)this << t;
946
2
        return *this;
947
2
    }
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <butil::IOBuf>(butil::IOBuf const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::http_parser>(brpc::http_parser const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <butil::ToPrintable>(butil::ToPrintable const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [46]>(char const (&) [46])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [34]>(char const (&) [34])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [70]>(char const (&) [70])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <butil::EndPoint>(butil::EndPoint const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [57]>(char const (&) [57])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [38]>(char const (&) [38])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::Socket>(brpc::Socket const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <butil::fd_guard>(butil::fd_guard const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::SSLError>(brpc::SSLError const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [45]>(char const (&) [45])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [103]>(char const (&) [103])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [60]>(char const (&) [60])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::Destroyable*>(brpc::Destroyable* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [65]>(char const (&) [65])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [73]>(char const (&) [73])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [79]>(char const (&) [79])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [43]>(char const (&) [43])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [67]>(char const (&) [67])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [48]>(char const (&) [48])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [101]>(char const (&) [101])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [47]>(char const (&) [47])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [63]>(char const (&) [63])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [77]>(char const (&) [77])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [163]>(char const (&) [163])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [217]>(char const (&) [217])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [58]>(char const (&) [58])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [54]>(char const (&) [54])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [118]>(char const (&) [118])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [74]>(char const (&) [74])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [91]>(char const (&) [91])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <int*>(int* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <bthread::KeyTable*>(bthread::KeyTable* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <bthread_key_t>(bthread_key_t const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <bthread_keytable_pool_t*>(bthread_keytable_pool_t* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [75]>(char const (&) [75])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <bthread::TaskControl*>(bthread::TaskControl* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::EventDispatcher*>(brpc::EventDispatcher* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [82]>(char const (&) [82])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <bthread_id_t>(bthread_id_t const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [55]>(char const (&) [55])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::policy::ConsistentHashingLoadBalancerType>(brpc::policy::ConsistentHashingLoadBalancerType const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [61]>(char const (&) [61])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::ServerNode>(brpc::ServerNode const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::URI>(brpc::URI const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [256]>(char const (&) [256])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <unsigned char>(unsigned char const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::StreamUserData*>(brpc::StreamUserData* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::policy::H2UnsentRequest>(brpc::policy::H2UnsentRequest const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::CompressType>(brpc::CompressType const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::policy::H2UnsentResponse>(brpc::policy::H2UnsentResponse const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::policy::HuluCompressType>(brpc::policy::HuluCompressType const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::ServerId>(brpc::ServerId const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [108]>(char const (&) [108])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::RedisCommandHandlerResult>(brpc::RedisCommandHandlerResult const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::RedisResponse>(brpc::RedisResponse const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::RedisRequest>(brpc::RedisRequest const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::policy::RtmpContext*>(brpc::policy::RtmpContext* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::policy::RtmpChunkType>(brpc::policy::RtmpChunkType const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::RtmpLimitType>(brpc::RtmpLimitType const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::RtmpAudioMessage>(brpc::RtmpAudioMessage const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::RtmpVideoMessage>(brpc::RtmpVideoMessage const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <butil::Status>(butil::Status const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::policy::SofaCompressType>(brpc::policy::SofaCompressType const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [81]>(char const (&) [81])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [72]>(char const (&) [72])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::ProtocolType>(brpc::ProtocolType const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [142]>(char const (&) [142])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::RedisReplyType>(brpc::RedisReplyType const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::DebugPrinter>(brpc::DebugPrinter const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::RestfulMethodPath>(brpc::RestfulMethodPath const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::RtmpClientImpl*>(brpc::RtmpClientImpl* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::AMFObject>(brpc::AMFObject const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::RtmpClientStream*>(brpc::RtmpClientStream* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::RtmpRetryingClientStream*>(brpc::RtmpRetryingClientStream* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::ChannelBase>(brpc::ChannelBase const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <short>(short const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::ChannelBase*>(brpc::ChannelBase* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::Acceptor*>(brpc::Acceptor* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [78]>(char const (&) [78])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <in_addr>(in_addr const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [139]>(char const (&) [139])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::CertInfo>(brpc::CertInfo const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::SocketMap*>(brpc::SocketMap* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::TrackMeSeverity>(brpc::TrackMeSeverity const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [123]>(char const (&) [123])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <float>(float const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <signed char>(signed char const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <mcpack2pb::StringWrapper>(mcpack2pb::StringWrapper const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <mcpack2pb::Serializer::GroupInfo>(mcpack2pb::Serializer::GroupInfo const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::Acceptor::Status>(brpc::Acceptor::Status const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::ProfilingType>(brpc::ProfilingType const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [85]>(char const (&) [85])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [106]>(char const (&) [106])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::Channel*>(brpc::Channel* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::Controller*>(brpc::Controller* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::ChecksumType>(brpc::ChecksumType const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <void (*)(int)>(void (* const&)(int))
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::SessionKVFlusher>(brpc::SessionKVFlusher const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [120]>(char const (&) [120])
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::Socket*>(brpc::Socket* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::IndexTable*>(brpc::IndexTable* const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <brpc::NamingServiceThread>(brpc::NamingServiceThread const&)
Unexecuted instantiation: logging::LogStream& logging::LogStream::operator<< <char [122]>(char const (&) [122])
948
949
    // Reset the log prefix: "I0711 15:14:01.830110 12735 server.cpp:93] "
950
    LogStream& SetPosition(const LogChar* file, int line, LogSeverity);
951
952
    // Reset the log prefix: "E0711 15:14:01.830110 12735 server.cpp:752 StartInternal] "
953
    LogStream& SetPosition(const LogChar* file, int line, const LogChar* func, LogSeverity);
954
955
    // Make FlushIfNeed() no-op once.
956
0
    LogStream& DontFlushOnce() {
957
0
        _noflush = true;
958
0
        return *this;
959
0
    }
960
961
0
    LogStream& SetCheck() {
962
0
        _is_check = true;
963
0
        return *this;
964
0
    }
965
966
0
    LogStream& SetBacktrace() {
967
0
        _backtrace = true;
968
0
        return *this;
969
0
    }
970
971
10.6k
    bool empty() const { return pbase() == pptr(); }
972
973
    butil::StringPiece content() const
974
5.34k
    { return butil::StringPiece(pbase(), pptr() - pbase()); }
975
976
    std::string content_str() const
977
0
    { return std::string(pbase(), pptr() - pbase()); }
978
979
0
    const LogChar* file() const { return _file; }
980
0
    int line() const { return _line; }
981
0
    const LogChar* func() const { return _func; }
982
0
    LogSeverity severity() const { return _severity; }
983
984
private:
985
    void FlushWithoutReset();
986
987
    // Flush log into sink(if registered) or stderr.
988
    // NOTE: make this method private to limit the callsites so that the
989
    // stack-frame removal in FlushWithoutReset() is always safe.
990
5.34k
    inline void Flush() {
991
5.34k
        const bool res = _noflush;
992
5.34k
        _noflush = false;
993
5.34k
        if (!res) {
994
            // Save and restore thread-local error code after Flush().
995
5.34k
            const SystemErrorCode err = GetLastSystemErrorCode();
996
5.34k
            FlushWithoutReset();
997
5.34k
            reset();
998
5.34k
            clear();
999
5.34k
            SetLastSystemErrorCode(err);
1000
5.34k
            _is_check = false;
1001
5.34k
            _backtrace = false;
1002
5.34k
        }
1003
5.34k
    }
1004
1005
    const LogChar* _file;
1006
    int _line;
1007
    const LogChar* _func;
1008
    LogSeverity _severity;
1009
    bool _noflush;
1010
    bool _is_check;
1011
    bool _backtrace;
1012
};
1013
1014
// This class more or less represents a particular log message.  You
1015
// create an instance of LogMessage and then stream stuff to it.
1016
// When you finish streaming to it, ~LogMessage is called and the
1017
// full message gets streamed to the appropriate destination if `noflush'
1018
// is not present.
1019
//
1020
// You shouldn't actually use LogMessage's constructor to log things,
1021
// though.  You should use the LOG() macro (and variants thereof)
1022
// above.
1023
class BUTIL_EXPORT LogMessage {
1024
public:
1025
    // Used for LOG(severity).
1026
    LogMessage(const char* file, int line, LogSeverity severity);
1027
    LogMessage(const char* file, int line, const char* func,
1028
               LogSeverity severity);
1029
1030
    // Used for CHECK_EQ(), etc. Takes ownership of the given string.
1031
    // Implied severity = BLOG_FATAL.
1032
    LogMessage(const char* file, int line, std::string* result);
1033
    LogMessage(const char* file, int line, const char* func,
1034
               std::string* result);
1035
1036
    // Used for DCHECK_EQ(), etc. Takes ownership of the given string.
1037
    LogMessage(const char* file, int line, LogSeverity severity,
1038
               std::string* result);
1039
    LogMessage(const char* file, int line, const char* func,
1040
               LogSeverity severity, std::string* result);
1041
1042
    ~LogMessage();
1043
1044
5.34k
    LogStream& stream() { return *_stream; }
1045
1046
private:
1047
    DISALLOW_COPY_AND_ASSIGN(LogMessage);
1048
1049
    // The real data is inside LogStream which may be cached thread-locally.
1050
    LogStream* _stream;
1051
};
1052
1053
// A non-macro interface to the log facility; (useful
1054
// when the logging level is not a compile-time constant).
1055
0
inline void LogAtLevel(int const log_level, const butil::StringPiece &msg) {
1056
0
    LogMessage(__FILE__, __LINE__, __func__,
1057
0
               log_level).stream() << msg;
1058
0
}
1059
1060
// This class is used to explicitly ignore values in the conditional
1061
// logging macros.  This avoids compiler warnings like "value computed
1062
// is not used" and "statement has no effect".
1063
class LogMessageVoidify {
1064
public:
1065
5.34k
    LogMessageVoidify() { }
1066
    // This has to be an operator with a precedence lower than << but
1067
    // higher than ?:
1068
5.34k
    void operator&(std::ostream&) { }
1069
};
1070
1071
#if defined(OS_WIN)
1072
// Appends a formatted system message of the GetLastError() type.
1073
class BUTIL_EXPORT Win32ErrorLogMessage {
1074
public:
1075
    Win32ErrorLogMessage(const char* file,
1076
                         int line,
1077
                         LogSeverity severity,
1078
                         SystemErrorCode err);
1079
1080
    Win32ErrorLogMessage(const char* file,
1081
                         int line,
1082
                         const char* func,
1083
                         LogSeverity severity,
1084
                         SystemErrorCode err);
1085
1086
    // Appends the error message before destructing the encapsulated class.
1087
    ~Win32ErrorLogMessage();
1088
1089
    LogStream& stream() { return log_message_.stream(); }
1090
1091
private:
1092
    SystemErrorCode err_;
1093
    LogMessage log_message_;
1094
1095
    DISALLOW_COPY_AND_ASSIGN(Win32ErrorLogMessage);
1096
};
1097
#elif defined(OS_POSIX)
1098
// Appends a formatted system message of the errno type
1099
class BUTIL_EXPORT ErrnoLogMessage {
1100
public:
1101
    ErrnoLogMessage(const char* file,
1102
                    int line,
1103
                    LogSeverity severity,
1104
                    SystemErrorCode err);
1105
1106
    ErrnoLogMessage(const char* file,
1107
                    int line,
1108
                    const char* func,
1109
                    LogSeverity severity,
1110
                    SystemErrorCode err);
1111
1112
    // Appends the error message before destructing the encapsulated class.
1113
    ~ErrnoLogMessage();
1114
1115
0
    LogStream& stream() { return log_message_.stream(); }
1116
1117
private:
1118
    SystemErrorCode err_;
1119
    LogMessage log_message_;
1120
1121
    DISALLOW_COPY_AND_ASSIGN(ErrnoLogMessage);
1122
};
1123
#endif  // OS_WIN
1124
1125
// Closes the log file explicitly if open.
1126
// NOTE: Since the log file is opened as necessary by the action of logging
1127
//       statements, there's no guarantee that it will stay closed
1128
//       after this call.
1129
BUTIL_EXPORT void CloseLogFile();
1130
1131
// Async signal safe logging mechanism.
1132
BUTIL_EXPORT void RawLog(int level, const char* message);
1133
1134
#define RAW_LOG(level, message)                         \
1135
    ::logging::RawLog(::logging::BLOG_##level, message)
1136
1137
#define RAW_CHECK(condition, message)                                   \
1138
    do {                                                                \
1139
        if (!(condition))                                               \
1140
            ::logging::RawLog(::logging::BLOG_FATAL, "Check failed: " #condition "\n"); \
1141
    } while (0)
1142
1143
#if defined(OS_WIN)
1144
// Returns the default log file path.
1145
BUTIL_EXPORT std::wstring GetLogFileFullPath();
1146
#endif
1147
1148
0
inline LogStream& noflush(LogStream& ls) {
1149
0
    ls.DontFlushOnce();
1150
0
    return ls;
1151
0
}
1152
1153
}  // namespace logging
1154
1155
using ::logging::noflush;
1156
using ::logging::VLogSitePrinter;
1157
using ::logging::print_vlog_sites;
1158
1159
// These functions are provided as a convenience for logging, which is where we
1160
// use streams (it is against Google style to use streams in other places). It
1161
// is designed to allow you to emit non-ASCII Unicode strings to the log file,
1162
// which is normally ASCII. It is relatively slow, so try not to use it for
1163
// common cases. Non-ASCII characters will be converted to UTF-8 by these
1164
// operators.
1165
BUTIL_EXPORT std::ostream& operator<<(std::ostream& out, const wchar_t* wstr);
1166
0
inline std::ostream& operator<<(std::ostream& out, const std::wstring& wstr) {
1167
0
    return out << wstr.c_str();
1168
0
}
1169
1170
// The NOTIMPLEMENTED() macro annotates codepaths which have
1171
// not been implemented yet.
1172
//
1173
// The implementation of this macro is controlled by NOTIMPLEMENTED_POLICY:
1174
//   0 -- Do nothing (stripped by compiler)
1175
//   1 -- Warn at compile time
1176
//   2 -- Fail at compile time
1177
//   3 -- Fail at runtime (DCHECK)
1178
//   4 -- [default] LOG(ERROR) at runtime
1179
//   5 -- LOG(ERROR) at runtime, only once per call-site
1180
1181
#endif // BRPC_WITH_GLOG
1182
1183
#ifndef NOTIMPLEMENTED_POLICY
1184
#if defined(OS_ANDROID) && defined(OFFICIAL_BUILD)
1185
#define NOTIMPLEMENTED_POLICY 0
1186
#else
1187
// Select default policy: LOG(ERROR)
1188
#define NOTIMPLEMENTED_POLICY 4
1189
#endif
1190
#endif // NOTIMPLEMENTED_POLICY
1191
1192
#if defined(COMPILER_GCC)
1193
// On Linux, with GCC, we can use __PRETTY_FUNCTION__ to get the demangled name
1194
// of the current function in the NOTIMPLEMENTED message.
1195
#define NOTIMPLEMENTED_MSG "Not implemented reached in " << __PRETTY_FUNCTION__
1196
#else
1197
#define NOTIMPLEMENTED_MSG "NOT IMPLEMENTED"
1198
#endif
1199
1200
#if NOTIMPLEMENTED_POLICY == 0
1201
#define NOTIMPLEMENTED() BAIDU_EAT_STREAM_PARAMS
1202
#elif NOTIMPLEMENTED_POLICY == 1
1203
// TODO, figure out how to generate a warning
1204
#define NOTIMPLEMENTED() COMPILE_ASSERT(false, NOT_IMPLEMENTED)
1205
#elif NOTIMPLEMENTED_POLICY == 2
1206
#define NOTIMPLEMENTED() COMPILE_ASSERT(false, NOT_IMPLEMENTED)
1207
#elif NOTIMPLEMENTED_POLICY == 3
1208
#define NOTIMPLEMENTED() NOTREACHED()
1209
#elif NOTIMPLEMENTED_POLICY == 4
1210
#define NOTIMPLEMENTED() LOG(ERROR) << NOTIMPLEMENTED_MSG
1211
#elif NOTIMPLEMENTED_POLICY == 5
1212
#define NOTIMPLEMENTED() do {                                   \
1213
        static bool logged_once = false;                        \
1214
        LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;      \
1215
        logged_once = true;                                     \
1216
    } while(0);                                                 \
1217
    BAIDU_EAT_STREAM_PARAMS
1218
#endif
1219
1220
#if defined(NDEBUG) && defined(OS_CHROMEOS)
1221
#define NOTREACHED() LOG(ERROR) << "NOTREACHED() hit in "       \
1222
    << __FUNCTION__ << ". "
1223
#else
1224
2
#define NOTREACHED() DCHECK(false)
1225
#endif
1226
1227
// Helper macro included by all *_EVERY_N macros.
1228
#define BAIDU_LOG_IF_EVERY_N_IMPL(logifmacro, severity, condition, N)   \
1229
0
    static ::butil::subtle::Atomic32 BAIDU_CONCAT(logeveryn_, __LINE__) = -1; \
1230
0
    const static int BAIDU_CONCAT(logeveryn_sc_, __LINE__) = (N);       \
1231
0
    const int BAIDU_CONCAT(logeveryn_c_, __LINE__) =                    \
1232
0
        ::butil::subtle::NoBarrier_AtomicIncrement(&BAIDU_CONCAT(logeveryn_, __LINE__), 1); \
1233
0
    logifmacro(severity, (condition) && BAIDU_CONCAT(logeveryn_c_, __LINE__) / \
1234
0
               BAIDU_CONCAT(logeveryn_sc_, __LINE__) * BAIDU_CONCAT(logeveryn_sc_, __LINE__) \
1235
0
               == BAIDU_CONCAT(logeveryn_c_, __LINE__))
1236
1237
// Helper macro included by all *_FIRST_N macros.
1238
#define BAIDU_LOG_IF_FIRST_N_IMPL(logifmacro, severity, condition, N)   \
1239
0
    static ::butil::subtle::Atomic32 BAIDU_CONCAT(logfstn_, __LINE__) = 0; \
1240
0
    logifmacro(severity, (condition) && BAIDU_CONCAT(logfstn_, __LINE__) < N && \
1241
0
               ::butil::subtle::NoBarrier_AtomicIncrement(&BAIDU_CONCAT(logfstn_, __LINE__), 1) <= N)
1242
1243
// Helper macro included by all *_EVERY_SECOND macros.
1244
#define BAIDU_LOG_IF_EVERY_SECOND_IMPL(logifmacro, severity, condition) \
1245
0
    static ::butil::subtle::Atomic64 BAIDU_CONCAT(logeverys_, __LINE__) = 0; \
1246
0
    const int64_t BAIDU_CONCAT(logeverys_ts_, __LINE__) = ::butil::gettimeofday_us(); \
1247
0
    const int64_t BAIDU_CONCAT(logeverys_seen_, __LINE__) = BAIDU_CONCAT(logeverys_, __LINE__); \
1248
0
    logifmacro(severity, (condition) && BAIDU_CONCAT(logeverys_ts_, __LINE__) >= \
1249
0
               (BAIDU_CONCAT(logeverys_seen_, __LINE__) + 1000000L) &&  \
1250
0
               ::butil::subtle::NoBarrier_CompareAndSwap(                \
1251
0
                   &BAIDU_CONCAT(logeverys_, __LINE__),                 \
1252
0
                   BAIDU_CONCAT(logeverys_seen_, __LINE__),             \
1253
0
                   BAIDU_CONCAT(logeverys_ts_, __LINE__))               \
1254
0
               == BAIDU_CONCAT(logeverys_seen_, __LINE__))
1255
1256
// ===============================================================
1257
1258
// Print a log for at most once. (not present in glog)
1259
// Almost zero overhead when the log was printed.
1260
#ifndef LOG_ONCE
1261
0
# define LOG_ONCE(severity) LOG_FIRST_N(severity, 1)
1262
# define LOG_BACKTRACE_ONCE(severity) LOG_BACKTRACE_FIRST_N(severity, 1)
1263
# define LOG_IF_ONCE(severity, condition) LOG_IF_FIRST_N(severity, condition, 1)
1264
#ifndef LOG_BACKTRACE_IF_ONCE
1265
# define LOG_BACKTRACE_IF_ONCE(severity, condition) \
1266
    LOG_BACKTRACE_IF_FIRST_N(severity, condition, 1)
1267
#endif // LOG_BACKTRACE_IF_ONCE
1268
#endif // LOG_ONCE
1269
1270
// Print a log after every N calls. First call always prints.
1271
// Each call to this macro has a cost of relaxed atomic increment.
1272
// The corresponding macro in glog is not thread-safe while this is.
1273
#ifndef LOG_EVERY_N
1274
# define LOG_EVERY_N(severity, N)                                \
1275
0
     BAIDU_LOG_IF_EVERY_N_IMPL(LOG_IF, severity, true, N)
1276
# define LOG_IF_EVERY_N(severity, condition, N)                  \
1277
     BAIDU_LOG_IF_EVERY_N_IMPL(LOG_IF, severity, condition, N)
1278
#endif // LOG_EVERY_N
1279
1280
// Print logs for first N calls.
1281
// Almost zero overhead when the log was printed for N times
1282
// The corresponding macro in glog is not thread-safe while this is.
1283
#ifndef LOG_FIRST_N
1284
# define LOG_FIRST_N(severity, N)                                \
1285
0
     BAIDU_LOG_IF_FIRST_N_IMPL(LOG_IF, severity, true, N)
1286
#ifndef LOG_BACKTRACE_FIRST_N
1287
# define LOG_BACKTRACE_FIRST_N(severity, N)                          \
1288
     BAIDU_LOG_IF_FIRST_N_IMPL(LOG_BACKTRACE_IF, severity, true, N)
1289
#endif // LOG_BACKTRACE_FIRST_N
1290
# define LOG_IF_FIRST_N(severity, condition, N)                  \
1291
     BAIDU_LOG_IF_FIRST_N_IMPL(LOG_IF, severity, condition, N)
1292
#ifndef LOG_BACKTRACE_IF_FIRST_N
1293
# define LOG_BACKTRACE_IF_FIRST_N(severity, condition, N)            \
1294
     BAIDU_LOG_IF_FIRST_N_IMPL(LOG_BACKTRACE_IF, severity, condition, N)
1295
#endif // LOG_BACKTRACE_IF_FIRST_N
1296
#endif // LOG_FIRST_N
1297
1298
// Print a log every second. (not present in glog). First call always prints.
1299
// Each call to this macro has a cost of calling gettimeofday.
1300
#ifndef LOG_EVERY_SECOND
1301
# define LOG_EVERY_SECOND(severity)                                \
1302
0
     BAIDU_LOG_IF_EVERY_SECOND_IMPL(LOG_IF, severity, true)
1303
# define LOG_IF_EVERY_SECOND(severity, condition)                \
1304
     BAIDU_LOG_IF_EVERY_SECOND_IMPL(LOG_IF, severity, condition)
1305
#endif // LOG_EVERY_SECOND
1306
1307
#ifndef PLOG_EVERY_N
1308
# define PLOG_EVERY_N(severity, N)                               \
1309
     BAIDU_LOG_IF_EVERY_N_IMPL(PLOG_IF, severity, true, N)
1310
# define PLOG_IF_EVERY_N(severity, condition, N)                 \
1311
     BAIDU_LOG_IF_EVERY_N_IMPL(PLOG_IF, severity, condition, N)
1312
#endif // PLOG_EVERY_N
1313
1314
#ifndef PLOG_FIRST_N
1315
# define PLOG_FIRST_N(severity, N)                               \
1316
     BAIDU_LOG_IF_FIRST_N_IMPL(PLOG_IF, severity, true, N)
1317
# define PLOG_IF_FIRST_N(severity, condition, N)                 \
1318
     BAIDU_LOG_IF_FIRST_N_IMPL(PLOG_IF, severity, condition, N)
1319
#endif // PLOG_FIRST_N
1320
1321
#ifndef PLOG_ONCE
1322
# define PLOG_ONCE(severity) PLOG_FIRST_N(severity, 1)
1323
# define PLOG_IF_ONCE(severity, condition) PLOG_IF_FIRST_N(severity, condition, 1)
1324
#endif // PLOG_ONCE
1325
1326
#ifndef PLOG_EVERY_SECOND
1327
# define PLOG_EVERY_SECOND(severity)                             \
1328
0
     BAIDU_LOG_IF_EVERY_SECOND_IMPL(PLOG_IF, severity, true)
1329
# define PLOG_IF_EVERY_SECOND(severity, condition)                       \
1330
     BAIDU_LOG_IF_EVERY_SECOND_IMPL(PLOG_IF, severity, condition)
1331
#endif // PLOG_EVERY_SECOND
1332
1333
// DEBUG_MODE is for uses like
1334
//   if (DEBUG_MODE) foo.CheckThatFoo();
1335
// instead of
1336
//   #ifndef NDEBUG
1337
//     foo.CheckThatFoo();
1338
//   #endif
1339
//
1340
// We tie its state to ENABLE_DLOG.
1341
enum { DEBUG_MODE = DCHECK_IS_ON() };
1342
1343
1344
#endif  // BUTIL_LOGGING_H_