37
37
logstream
38
38
39
39
#define QUICHE_LOG_IF_IMPL (severity, condition ) \
40
- QUICHE_LOG_IMPL_INTERNAL ((condition) && quic::IsLogLevelEnabled(quic::severity), \
41
- quic::QuicLogEmitter(quic::severity).stream())
40
+ QUICHE_LOG_IMPL_INTERNAL ( \
41
+ QUICHE_IS_LOG_LEVEL_ENABLED (severity) && (condition), \
42
+ quic::QuicLogEmitter(quic::severity, __FILE__, __LINE__, __func__).stream())
42
43
43
44
#define QUICHE_LOG_IMPL (severity ) QUICHE_LOG_IF_IMPL(severity, true )
44
45
45
46
#define QUICHE_VLOG_IF_IMPL (verbosity, condition ) \
46
- QUICHE_LOG_IMPL_INTERNAL ((condition) && quic::IsVerboseLogEnabled(verbosity), \
47
- quic::QuicLogEmitter(quic::INFO).stream())
47
+ QUICHE_LOG_IMPL_INTERNAL ( \
48
+ quic::isVerboseLogEnabled (verbosity) && (condition), \
49
+ quic::QuicLogEmitter(quic::INFO, __FILE__, __LINE__, __func__).stream())
48
50
49
51
#define QUICHE_VLOG_IMPL (verbosity ) QUICHE_VLOG_IF_IMPL(verbosity, true )
50
52
58
60
#define QUICHE_LOG_EVERY_N_SEC_IMPL (severity, seconds ) QUICHE_LOG_IMPL(severity)
59
61
60
62
#define QUICHE_PLOG_IMPL (severity ) \
61
- QUICHE_LOG_IMPL_INTERNAL (quic::IsLogLevelEnabled(quic::severity), \
62
- quic::QuicLogEmitter(quic::severity).SetPerror().stream())
63
+ QUICHE_LOG_IMPL_INTERNAL ( \
64
+ QUICHE_IS_LOG_LEVEL_ENABLED (severity), \
65
+ quic::QuicLogEmitter(quic::severity, __FILE__, __LINE__, __func__).SetPerror().stream())
63
66
64
- #define QUICHE_LOG_INFO_IS_ON_IMPL () quic::IsLogLevelEnabled(quic:: INFO)
65
- #define QUICHE_LOG_WARNING_IS_ON_IMPL () quic::IsLogLevelEnabled(quic:: WARNING)
66
- #define QUICHE_LOG_ERROR_IS_ON_IMPL () quic::IsLogLevelEnabled(quic:: ERROR)
67
+ #define QUICHE_LOG_INFO_IS_ON_IMPL () QUICHE_IS_LOG_LEVEL_ENABLED( INFO)
68
+ #define QUICHE_LOG_WARNING_IS_ON_IMPL () QUICHE_IS_LOG_LEVEL_ENABLED( WARNING)
69
+ #define QUICHE_LOG_ERROR_IS_ON_IMPL () QUICHE_IS_LOG_LEVEL_ENABLED( ERROR)
67
70
68
- #define QUICHE_CHECK_IMPL (condition ) \
69
- QUICHE_LOG_IF_IMPL (FATAL, ABSL_PREDICT_FALSE(!(condition))) << "CHECK failed: " #condition " . "
71
+ #define QUICHE_CHECK_INNER_IMPL (condition, details ) \
72
+ QUICHE_LOG_IF_IMPL (FATAL, ABSL_PREDICT_FALSE(!(condition))) << details << ". "
70
73
71
- #define QUICHE_CHECK_GT_IMPL (a, b ) QUICHE_CHECK_IMPL((a) > (b))
72
- #define QUICHE_CHECK_GE_IMPL (a, b ) QUICHE_CHECK_IMPL((a) >= (b))
73
- #define QUICHE_CHECK_LT_IMPL (a, b ) QUICHE_CHECK_IMPL((a) < (b))
74
- #define QUICHE_CHECK_LE_IMPL (a, b ) QUICHE_CHECK_IMPL((a) <= (b))
75
- #define QUICHE_CHECK_NE_IMPL (a, b ) QUICHE_CHECK_IMPL((a) != (b))
76
- #define QUICHE_CHECK_EQ_IMPL (a, b ) QUICHE_CHECK_IMPL((a) == (b))
74
+ #define QUICHE_CHECK_IMPL (condition ) QUICHE_CHECK_INNER_IMPL(condition, " CHECK failed: " #condition)
75
+
76
+ #define QUICHE_CHECK_INNER_IMPL_OP (op, a, b ) \
77
+ QUICHE_CHECK_INNER_IMPL ((a)op(b), \
78
+ "CHECK failed: " #a " (=" << (a) << ") " #op " " #b " (=" << (b) << ")")
79
+
80
+ #define QUICHE_CHECK_GT_IMPL (a, b ) QUICHE_CHECK_INNER_IMPL_OP(>, a, b)
81
+ #define QUICHE_CHECK_GE_IMPL (a, b ) QUICHE_CHECK_INNER_IMPL_OP(>=, a, b)
82
+ #define QUICHE_CHECK_LT_IMPL (a, b ) QUICHE_CHECK_INNER_IMPL_OP(<, a, b)
83
+ #define QUICHE_CHECK_LE_IMPL (a, b ) QUICHE_CHECK_INNER_IMPL_OP(<=, a, b)
84
+ #define QUICHE_CHECK_NE_IMPL (a, b ) QUICHE_CHECK_INNER_IMPL_OP(!=, a, b)
85
+ #define QUICHE_CHECK_EQ_IMPL (a, b ) QUICHE_CHECK_INNER_IMPL_OP(==, a, b)
77
86
78
87
#ifdef NDEBUG
79
88
// Release build
87
96
#define QUICHE_DLOG_INFO_IS_ON_IMPL () 0
88
97
#define QUICHE_DLOG_EVERY_N_IMPL (severity, n ) QUICHE_COMPILED_OUT_LOG(false )
89
98
#define QUICHE_NOTREACHED_IMPL ()
99
+ #define QUICHE_DCHECK_GT_IMPL (a, b ) QUICHE_COMPILED_OUT_LOG((a) > (b))
100
+ #define QUICHE_DCHECK_GE_IMPL (a, b ) QUICHE_COMPILED_OUT_LOG((a) >= (b))
101
+ #define QUICHE_DCHECK_LT_IMPL (a, b ) QUICHE_COMPILED_OUT_LOG((a) < (b))
102
+ #define QUICHE_DCHECK_LE_IMPL (a, b ) QUICHE_COMPILED_OUT_LOG((a) <= (b))
103
+ #define QUICHE_DCHECK_NE_IMPL (a, b ) QUICHE_COMPILED_OUT_LOG((a) != (b))
104
+ #define QUICHE_DCHECK_EQ_IMPL (a, b ) QUICHE_COMPILED_OUT_LOG((a) == (b))
90
105
#else
91
106
// Debug build
92
107
#define QUICHE_DCHECK_IMPL (condition ) QUICHE_CHECK_IMPL(condition)
97
112
#define QUICHE_DLOG_INFO_IS_ON_IMPL () QUICHE_LOG_INFO_IS_ON_IMPL()
98
113
#define QUICHE_DLOG_EVERY_N_IMPL (severity, n ) QUICHE_LOG_EVERY_N_IMPL(severity, n)
99
114
#define QUICHE_NOTREACHED_IMPL () NOT_REACHED_GCOVR_EXCL_LINE
115
+ #define QUICHE_DCHECK_GT_IMPL (a, b ) QUICHE_CHECK_GT_IMPL(a, b)
116
+ #define QUICHE_DCHECK_GE_IMPL (a, b ) QUICHE_CHECK_GE_IMPL(a, b)
117
+ #define QUICHE_DCHECK_LT_IMPL (a, b ) QUICHE_CHECK_LT_IMPL(a, b)
118
+ #define QUICHE_DCHECK_LE_IMPL (a, b ) QUICHE_CHECK_LE_IMPL(a, b)
119
+ #define QUICHE_DCHECK_NE_IMPL (a, b ) QUICHE_CHECK_NE_IMPL(a, b)
120
+ #define QUICHE_DCHECK_EQ_IMPL (a, b ) QUICHE_CHECK_EQ_IMPL(a, b)
100
121
#endif
101
122
102
- #define QUICHE_DCHECK_GE_IMPL (a, b ) QUICHE_DCHECK_IMPL((a) >= (b))
103
- #define QUICHE_DCHECK_GT_IMPL (a, b ) QUICHE_DCHECK_IMPL((a) > (b))
104
- #define QUICHE_DCHECK_LT_IMPL (a, b ) QUICHE_DCHECK_IMPL((a) < (b))
105
- #define QUICHE_DCHECK_LE_IMPL (a, b ) QUICHE_DCHECK_IMPL((a) <= (b))
106
- #define QUICHE_DCHECK_NE_IMPL (a, b ) QUICHE_DCHECK_IMPL((a) != (b))
107
- #define QUICHE_DCHECK_EQ_IMPL (a, b ) QUICHE_DCHECK_IMPL((a) == (b))
108
-
109
123
#define QUICHE_PREDICT_FALSE_IMPL (x ) ABSL_PREDICT_FALSE(x)
110
124
111
125
namespace quic {
112
126
113
127
using QuicLogLevel = spdlog::level::level_enum;
114
128
129
+ static const QuicLogLevel TRACE = spdlog::level::trace;
130
+ static const QuicLogLevel DEBUG = spdlog::level::debug;
115
131
static const QuicLogLevel INFO = spdlog::level::info;
116
132
static const QuicLogLevel WARNING = spdlog::level::warn;
117
133
static const QuicLogLevel ERROR = spdlog::level::err;
@@ -126,7 +142,10 @@ static const QuicLogLevel DFATAL = FATAL;
126
142
127
143
class QuicLogEmitter {
128
144
public:
129
- explicit QuicLogEmitter (QuicLogLevel level);
145
+ // |file_name| and |function_name| MUST be valid for the lifetime of the QuicLogEmitter. This is
146
+ // guaranteed when passing __FILE__ and __func__.
147
+ explicit QuicLogEmitter (QuicLogLevel level, const char * file_name, int line,
148
+ const char * function_name);
130
149
131
150
~QuicLogEmitter ();
132
151
@@ -139,6 +158,9 @@ class QuicLogEmitter {
139
158
140
159
private:
141
160
const QuicLogLevel level_;
161
+ const char * file_name_;
162
+ int line_;
163
+ const char * function_name_;
142
164
const int saved_errno_;
143
165
bool is_perror_ = false ;
144
166
std::ostringstream stream_;
@@ -157,17 +179,27 @@ inline spdlog::logger& GetLogger() {
157
179
return Envoy::Logger::Registry::getLog (Envoy::Logger::Id::quic);
158
180
}
159
181
160
- inline bool IsLogLevelEnabled (QuicLogLevel level) { return level >= GetLogger ().level (); }
161
-
162
- int GetVerbosityLogThreshold ();
163
- void SetVerbosityLogThreshold (int new_verbosity);
164
-
165
- inline bool IsVerboseLogEnabled (int verbosity) {
166
- return IsLogLevelEnabled (INFO) && verbosity <= GetVerbosityLogThreshold ();
182
+ // This allows us to use QUICHE_CHECK(condition) from constexpr functions.
183
+ #define QUICHE_IS_LOG_LEVEL_ENABLED (severity ) quic::isLogLevelEnabled##severity()
184
+ #define QUICHE_IS_LOG_LEVEL_ENABLED_IMPL (severity ) \
185
+ inline bool isLogLevelEnabled##severity() { return quic::severity >= GetLogger ().level (); }
186
+ QUICHE_IS_LOG_LEVEL_ENABLED_IMPL (TRACE)
187
+ QUICHE_IS_LOG_LEVEL_ENABLED_IMPL (DEBUG)
188
+ QUICHE_IS_LOG_LEVEL_ENABLED_IMPL (INFO)
189
+ QUICHE_IS_LOG_LEVEL_ENABLED_IMPL (WARNING)
190
+ QUICHE_IS_LOG_LEVEL_ENABLED_IMPL (ERROR)
191
+ QUICHE_IS_LOG_LEVEL_ENABLED_IMPL (DFATAL)
192
+ inline bool constexpr isLogLevelEnabledFATAL () { return true ; }
193
+
194
+ int getVerbosityLogThreshold ();
195
+ void setVerbosityLogThreshold (int new_verbosity);
196
+
197
+ inline bool isVerboseLogEnabled (int verbosity) {
198
+ return QUICHE_IS_LOG_LEVEL_ENABLED (INFO) && verbosity <= getVerbosityLogThreshold ();
167
199
}
168
200
169
- bool IsDFatalExitDisabled ();
170
- void SetDFatalExitDisabled (bool is_disabled);
201
+ bool isDFatalExitDisabled ();
202
+ void setDFatalExitDisabled (bool is_disabled);
171
203
172
204
// QuicLogSink is used to capture logs emitted from the QUICHE_LOG... macros.
173
205
class QuicLogSink {
0 commit comments