36 #ifndef SHARED_LOGGER_H
37 #define SHARED_LOGGER_H
39 #if !(defined(__CUDACC__) || defined(NO_BOOST))
41 #include <boost/config.hpp>
42 #include <boost/log/sources/record_ostream.hpp>
46 #include <type_traits>
55 #include "../Shared/StackTrace.h"
72 #error "ERROR must not be globally defined during preprocessing."
77 namespace program_options {
78 class options_description;
80 namespace filesystem {
93 constexpr std::array<char const*, 4>
ChannelNames{
"IR",
"PTX",
"ASM",
"EXECUTOR"};
98 "Size of ChannelNames must equal number of Channels.");
100 "Size of ChannelSymbols must equal number of Channels.");
124 constexpr std::array<char, 8>
SeveritySymbols{
'4',
'3',
'2',
'1',
'I',
'W',
'E',
'F'};
127 "Size of SeverityNames must equal number of Severity levels.");
129 "Size of SeveritySymbols must equal number of Severity levels.");
147 static_assert(std::is_standard_layout<ThreadLocalIds>::value);
148 static_assert(std::is_trivial<ThreadLocalIds>::value);
169 : prev_local_ids_(prev_local_ids)
170 , thread_local_ids_(thread_local_ids)
174 : prev_local_ids_(prev_local_ids), enabled_(
true) {}
197 #if !(defined(__CUDACC__) || defined(NO_BOOST))
206 std::unique_ptr<boost::program_options::options_description>
options_;
226 boost::program_options::options_description
const&
get_options()
const;
233 void init(LogOptions
const&);
253 std::unique_ptr<boost::log::record_ostream>
stream_;
260 operator bool()
const;
262 boost::log::record_ostream&
stream(
char const* file,
int line);
272 return g_min_active_severity <= severity;
279 #define SLOG(severity_or_channel) \
280 if (auto _heavydb_logger_severity_or_channel_ = severity_or_channel; \
281 logger::fast_logging_check(_heavydb_logger_severity_or_channel_)) \
282 if (auto _heavydb_logger_ = logger::Logger(_heavydb_logger_severity_or_channel_)) \
283 _heavydb_logger_.stream(__FILE__, __LINE__)
285 #define LOG(tag) SLOG(logger::tag)
287 #define LOGGING(tag) logger::fast_logging_check(logger::tag)
289 #define VLOGGING(n) logger::fast_logging_check(logger::DEBUG##n)
291 #define CHECK(condition) \
292 if (BOOST_UNLIKELY(!(condition))) \
293 LOG(FATAL) << "Check failed: " #condition "\n" \
294 << "Stack trace:\n" \
295 << getCurrentStackTrace(1, nullptr, false)
297 #define CHECK_OP(OP, x, y) \
298 if (std::string* fatal_msg = logger::Check##OP(x, y, #x, #y)) \
299 LOG(FATAL) << *std::unique_ptr<std::string>(fatal_msg)
301 #define CHECK_EQ(x, y) CHECK_OP(EQ, x, y)
302 #define CHECK_NE(x, y) CHECK_OP(NE, x, y)
303 #define CHECK_LT(x, y) CHECK_OP(LT, x, y)
304 #define CHECK_LE(x, y) CHECK_OP(LE, x, y)
305 #define CHECK_GT(x, y) CHECK_OP(GT, x, y)
306 #define CHECK_GE(x, y) CHECK_OP(GE, x, y)
308 template <
typename X,
typename Y>
313 char const* op_str) {
314 std::stringstream ss;
315 ss <<
"Check failed: " << xstr << op_str << ystr <<
" (" << x << op_str << y <<
")\n";
317 return new std::string(ss.str());
321 #define HEAVYDB_CHECKOP_FUNCTION(name, op) \
322 template <typename X, typename Y> \
323 inline std::string* Check##name( \
324 X const& x, Y const& y, char const* xstr, char const* ystr) { \
325 if (BOOST_LIKELY(x op y)) \
328 return logger::check_failed(x, y, xstr, ystr, " " #op " "); \
336 #undef HEAVYDB_CHECKOP_FUNCTION
338 #define UNREACHABLE() LOG(FATAL) << "UNREACHABLE "
344 template <Severity severity>
352 template <
typename T>
353 #ifndef SUPPRESS_NULL_LOGGER_DEPRECATION_WARNINGS
365 #define LOG(severity) logger::NullLogger<logger::Severity::severity>()
367 #define LOGGING(tag) false
369 #define VLOGGING(n) false
371 #define CHECK(condition) LOG_IF(FATAL, !(condition))
373 #define CHECK_EQ(x, y) CHECK((x) == (y))
374 #define CHECK_NE(x, y) CHECK((x) != (y))
375 #define CHECK_LT(x, y) CHECK((x) < (y))
376 #define CHECK_LE(x, y) CHECK((x) <= (y))
377 #define CHECK_GT(x, y) CHECK((x) > (y))
378 #define CHECK_GE(x, y) CHECK((x) >= (y))
380 #define UNREACHABLE() LOG(FATAL)
384 #define LOG_IF(severity, condition) \
388 #define VLOG(n) LOG(DEBUG##n)
412 #define DEBUG_TIMER(name) logger::DebugTimer(logger::INFO, __FILE__, __LINE__, name)
417 #define DEBUG_TIMER_NEW_THREAD(parent_thread_id) \
419 if (g_enable_debug_timer) \
420 logger::debug_timer_new_thread(parent_thread_id); \
425 #endif // SHARED_LOGGER_H
std::unique_ptr< boost::program_options::options_description > options_
std::set< Channel > Channels
std::string stopAndGetJson()
LocalIdsScopeGuard(ThreadLocalIds const prev_local_ids, ThreadLocalIds const thread_local_ids)
ThreadLocalIds thread_local_ids_
std::unique_ptr< boost::log::record > record_
LogOptions(char const *argv0)
bool g_enable_debug_timer
std::string getCurrentStackTrace(uint32_t num_frames_to_skip, const char *stop_at_this_frame, bool skip_void_and_stl_frames)
ThreadLocalIds prev_local_ids_
fs::path get_log_dir_path()
#define HEAVYDB_CHECKOP_FUNCTION(name, op)
void set_once_fatal_func(FatalFunc fatal_func)
ThreadLocalIds(RequestId const request_id, ThreadId const thread_id)
void(*)() noexcept FatalFunc
LocalIdsScopeGuard & operator=(LocalIdsScopeGuard &&rhs)
constexpr std::array< char, 8 > SeveritySymbols
bool fast_logging_check(Channel)
void init(LogOptions const &log_opts)
Severity g_min_active_severity
void debug_timer_new_thread(ThreadId const parent_thread_id)
RequestId set_new_request_id()
constexpr std::array< char const *, 4 > ChannelNames
void set_request_id(RequestId const request_id)
BOOST_NOINLINE std::string * check_failed(X const &x, Y const &y, char const *xstr, char const *ystr, char const *op_str)
bool g_enable_smem_group_by true
DebugTimer & operator=(DebugTimer const &)=delete
DebugTimer(DebugTimer const &)=delete
std::unique_ptr< boost::log::record_ostream > stream_
LocalIdsScopeGuard setNewThreadId() const
boost::log::formatting_ostream & operator<<(boost::log::formatting_ostream &strm, boost::log::to_log_manip< Channel, tag::channel > const &manip)
constexpr std::array< char const *, 8 > SeverityNames
constexpr std::array< char, 4 > ChannelSymbols
std::unique_ptr< boost::filesystem::path > log_dir_
bool g_any_active_channels
boost::program_options::options_description const & get_options() const
std::string file_name_pattern_
void set_base_path(std::string const &base_path)
boost::filesystem::path full_log_dir() const
LocalIdsScopeGuard(LocalIdsScopeGuard &&rhs)
ThreadLocalIds thread_local_ids()
boost::log::record_ostream & stream(char const *file, int line)
void parse_command_line(int, char const *const *)