-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Expand file tree
/
Copy pathlogging.h
More file actions
251 lines (206 loc) · 8.92 KB
/
logging.h
File metadata and controls
251 lines (206 loc) · 8.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#pragma once
#ifdef GANDIVA_IR
// The LLVM IR code doesn't have an NDEBUG mode. And, it shouldn't include references to
// streams or stdc++. So, making the DCHECK calls void in that case.
# define ARROW_IGNORE_EXPR(expr) ((void)(expr))
# define ARROW_DCHECK(condition) ARROW_IGNORE_EXPR(condition)
# define ARROW_DCHECK_OK(status) ARROW_IGNORE_EXPR(status)
# define ARROW_DCHECK_EQ(val1, val2) ARROW_IGNORE_EXPR(val1)
# define ARROW_DCHECK_NE(val1, val2) ARROW_IGNORE_EXPR(val1)
# define ARROW_DCHECK_LE(val1, val2) ARROW_IGNORE_EXPR(val1)
# define ARROW_DCHECK_LT(val1, val2) ARROW_IGNORE_EXPR(val1)
# define ARROW_DCHECK_GE(val1, val2) ARROW_IGNORE_EXPR(val1)
# define ARROW_DCHECK_GT(val1, val2) ARROW_IGNORE_EXPR(val1)
#else // !GANDIVA_IR
# include <memory>
# include <ostream>
# include <string>
# include "arrow/util/macros.h"
# include "arrow/util/visibility.h"
namespace arrow {
namespace util {
enum class ArrowLogLevel : int {
ARROW_TRACE = -2,
ARROW_DEBUG = -1,
ARROW_INFO = 0,
ARROW_WARNING = 1,
ARROW_ERROR = 2,
ARROW_FATAL = 3
};
# define ARROW_LOG_INTERNAL(level) ::arrow::util::ArrowLog(__FILE__, __LINE__, level)
# define ARROW_LOG(level) ARROW_LOG_INTERNAL(::arrow::util::ArrowLogLevel::ARROW_##level)
# define ARROW_IGNORE_EXPR(expr) ((void)(expr))
# define ARROW_CHECK_OR_LOG(condition, level) \
ARROW_PREDICT_TRUE(condition) \
? ARROW_IGNORE_EXPR(0) \
: ::arrow::util::Voidify() & ARROW_LOG(level) << " Check failed: " #condition " "
# define ARROW_CHECK(condition) ARROW_CHECK_OR_LOG(condition, FATAL)
// If 'to_call' returns a bad status, CHECK immediately with a logged message
// of 'msg' followed by the status.
# define ARROW_CHECK_OK_PREPEND(to_call, msg, level) \
do { \
::arrow::Status _s = ::arrow::ToStatus(to_call); \
ARROW_CHECK_OR_LOG(_s.ok(), level) \
<< "Operation failed: " << ARROW_STRINGIFY(to_call) << "\n" \
<< (msg) << ": " << _s.ToString(); \
} while (false)
// If the status is bad, CHECK immediately, appending the status to the
// logged message.
# define ARROW_CHECK_OK(s) ARROW_CHECK_OK_PREPEND(s, "Bad status", FATAL)
# define ARROW_CHECK_EQ(val1, val2) ARROW_CHECK((val1) == (val2))
# define ARROW_CHECK_NE(val1, val2) ARROW_CHECK((val1) != (val2))
# define ARROW_CHECK_LE(val1, val2) ARROW_CHECK((val1) <= (val2))
# define ARROW_CHECK_LT(val1, val2) ARROW_CHECK((val1) < (val2))
# define ARROW_CHECK_GE(val1, val2) ARROW_CHECK((val1) >= (val2))
# define ARROW_CHECK_GT(val1, val2) ARROW_CHECK((val1) > (val2))
# ifdef NDEBUG
# define ARROW_DFATAL ::arrow::util::ArrowLogLevel::ARROW_WARNING
// CAUTION: DCHECK_OK() always evaluates its argument, but other DCHECK*() macros
// only do so in debug mode.
# define ARROW_DCHECK(condition) \
while (false) ARROW_IGNORE_EXPR(condition); \
while (false) ::arrow::util::detail::NullLog()
# define ARROW_DCHECK_OK(s) \
ARROW_IGNORE_EXPR(s); \
while (false) ::arrow::util::detail::NullLog()
# define ARROW_DCHECK_EQ(val1, val2) \
while (false) ARROW_IGNORE_EXPR(val1); \
while (false) ARROW_IGNORE_EXPR(val2); \
while (false) ::arrow::util::detail::NullLog()
# define ARROW_DCHECK_NE(val1, val2) \
while (false) ARROW_IGNORE_EXPR(val1); \
while (false) ARROW_IGNORE_EXPR(val2); \
while (false) ::arrow::util::detail::NullLog()
# define ARROW_DCHECK_LE(val1, val2) \
while (false) ARROW_IGNORE_EXPR(val1); \
while (false) ARROW_IGNORE_EXPR(val2); \
while (false) ::arrow::util::detail::NullLog()
# define ARROW_DCHECK_LT(val1, val2) \
while (false) ARROW_IGNORE_EXPR(val1); \
while (false) ARROW_IGNORE_EXPR(val2); \
while (false) ::arrow::util::detail::NullLog()
# define ARROW_DCHECK_GE(val1, val2) \
while (false) ARROW_IGNORE_EXPR(val1); \
while (false) ARROW_IGNORE_EXPR(val2); \
while (false) ::arrow::util::detail::NullLog()
# define ARROW_DCHECK_GT(val1, val2) \
while (false) ARROW_IGNORE_EXPR(val1); \
while (false) ARROW_IGNORE_EXPR(val2); \
while (false) ::arrow::util::detail::NullLog()
# else
# define ARROW_DFATAL ::arrow::util::ArrowLogLevel::ARROW_FATAL
# define ARROW_DCHECK ARROW_CHECK
# define ARROW_DCHECK_OK ARROW_CHECK_OK
# define ARROW_DCHECK_EQ ARROW_CHECK_EQ
# define ARROW_DCHECK_NE ARROW_CHECK_NE
# define ARROW_DCHECK_LE ARROW_CHECK_LE
# define ARROW_DCHECK_LT ARROW_CHECK_LT
# define ARROW_DCHECK_GE ARROW_CHECK_GE
# define ARROW_DCHECK_GT ARROW_CHECK_GT
# endif // NDEBUG
// This code is adapted from
// https://github.com/ray-project/ray/blob/master/src/ray/util/logging.h.
// To make the logging lib pluggable with other logging libs and make
// the implementation unawared by the user, ArrowLog is only a declaration
// which hide the implementation into logging.cc file.
// In logging.cc, we can choose different log libs using different macros.
// This is also a null log which does not output anything.
class ARROW_EXPORT ArrowLogBase {
public:
virtual ~ArrowLogBase() {}
virtual bool IsEnabled() const { return false; }
template <typename T>
ArrowLogBase& operator<<(const T& t) {
if (IsEnabled()) {
Stream() << t;
}
return *this;
}
protected:
virtual std::ostream& Stream() = 0;
};
class ARROW_EXPORT ArrowLog : public ArrowLogBase {
public:
ArrowLog(const char* file_name, int line_number, ArrowLogLevel severity);
~ArrowLog() override;
/// Return whether or not current logging instance is enabled.
///
/// \return True if logging is enabled and false otherwise.
bool IsEnabled() const override;
/// The init function of arrow log for a program which should be called only once.
///
/// \param appName The app name which starts the log.
/// \param severity_threshold Logging threshold for the program.
/// \param logDir Logging output file name. If empty, the log won't output to file.
static void StartArrowLog(const std::string& appName,
ArrowLogLevel severity_threshold = ArrowLogLevel::ARROW_INFO,
const std::string& logDir = "");
/// The shutdown function of arrow log, it should be used with StartArrowLog as a pair.
static void ShutDownArrowLog();
/// Install the failure signal handler to output call stack when crash.
/// If glog is not installed, this function won't do anything.
static void InstallFailureSignalHandler();
/// Uninstall the signal actions installed by InstallFailureSignalHandler.
static void UninstallSignalAction();
/// Return whether or not the log level is enabled in current setting.
///
/// \param log_level The input log level to test.
/// \return True if input log level is not lower than the threshold.
static bool IsLevelEnabled(ArrowLogLevel log_level);
private:
ARROW_DISALLOW_COPY_AND_ASSIGN(ArrowLog);
// Hide the implementation of log provider by void *.
// Otherwise, lib user may define the same macro to use the correct header file.
void* logging_provider_;
/// True if log messages should be logged and false if they should be ignored.
bool is_enabled_;
static ArrowLogLevel severity_threshold_;
protected:
std::ostream& Stream() override;
};
// This class make ARROW_CHECK compilation pass to change the << operator to void.
// This class is copied from glog.
class ARROW_EXPORT Voidify {
public:
Voidify() {}
// This has to be an operator with a precedence lower than << but
// higher than ?:
void operator&(ArrowLogBase&) {}
};
namespace detail {
/// @brief A helper for the nil log sink.
///
/// Using this helper is analogous to sending log messages to /dev/null:
/// nothing gets logged.
class NullLog {
public:
/// The no-op output operator.
///
/// @param [in] t
/// The object to send into the nil sink.
/// @return Reference to the updated object.
template <class T>
NullLog& operator<<(const T& t) {
return *this;
}
};
} // namespace detail
} // namespace util
} // namespace arrow
#endif // GANDIVA_IR