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>
69 #error "ERROR must not be globally defined during preprocessing."
74 namespace program_options {
75 class options_description;
77 namespace filesystem {
90 constexpr std::array<char const*, 3>
ChannelNames{
"IR",
"PTX",
"ASM"};
95 "Size of ChannelNames must equal number of Channels.");
97 "Size of ChannelSymbols must equal number of Channels.");
121 constexpr std::array<char, 8>
SeveritySymbols{
'4',
'3',
'2',
'1',
'I',
'W',
'E',
'F'};
124 "Size of SeverityNames must equal number of Severity levels.");
126 "Size of SeveritySymbols must equal number of Severity levels.");
128 #if !(defined(__CUDACC__) || defined(NO_BOOST))
137 std::unique_ptr<boost::program_options::options_description>
options_;
157 boost::program_options::options_description
const&
get_options()
const;
164 void init(LogOptions
const&);
184 std::unique_ptr<boost::log::record_ostream>
stream_;
191 operator bool()
const;
193 boost::log::record_ostream&
stream(
char const* file,
int line);
203 return g_min_active_severity <= severity;
210 #define SLOG(severity_or_channel) \
211 if (auto _omnisci_logger_severity_or_channel_ = severity_or_channel; \
212 logger::fast_logging_check(_omnisci_logger_severity_or_channel_)) \
213 if (auto _omnisci_logger_ = logger::Logger(_omnisci_logger_severity_or_channel_)) \
214 _omnisci_logger_.stream(__FILE__, __LINE__)
216 #define LOG(tag) SLOG(logger::tag)
218 #define LOGGING(tag) logger::fast_logging_check(logger::tag)
220 #define VLOGGING(n) logger::fast_logging_check(logger::DEBUG##n)
222 #define CHECK(condition) \
223 if (BOOST_UNLIKELY(!(condition))) \
224 LOG(FATAL) << "Check failed: " #condition " "
226 #define CHECK_OP(OP, x, y) \
227 if (std::string* fatal_msg = logger::Check##OP(x, y, #x, #y)) \
228 LOG(FATAL) << *std::unique_ptr<std::string>(fatal_msg)
230 #define CHECK_EQ(x, y) CHECK_OP(EQ, x, y)
231 #define CHECK_NE(x, y) CHECK_OP(NE, x, y)
232 #define CHECK_LT(x, y) CHECK_OP(LT, x, y)
233 #define CHECK_LE(x, y) CHECK_OP(LE, x, y)
234 #define CHECK_GT(x, y) CHECK_OP(GT, x, y)
235 #define CHECK_GE(x, y) CHECK_OP(GE, x, y)
237 template <
typename X,
typename Y>
242 char const* op_str) {
243 std::stringstream ss;
244 ss <<
"Check failed: " << xstr << op_str << ystr <<
" (" << x << op_str << y <<
") ";
245 return new std::string(ss.str());
249 #define OMINSCI_CHECKOP_FUNCTION(name, op) \
250 template <typename X, typename Y> \
251 inline std::string* Check##name( \
252 X const& x, Y const& y, char const* xstr, char const* ystr) { \
253 if (BOOST_LIKELY(x op y)) \
256 return logger::check_failed(x, y, xstr, ystr, " " #op " "); \
264 #undef OMINSCI_CHECKOP_FUNCTION
266 #define UNREACHABLE() LOG(FATAL) << "UNREACHABLE "
272 template <Severity severity>
280 template <
typename T>
281 #ifndef SUPPRESS_NULL_LOGGER_DEPRECATION_WARNINGS
293 #define LOG(severity) logger::NullLogger<logger::Severity::severity>()
295 #define LOGGING(tag) false
297 #define VLOGGING(n) false
299 #define CHECK(condition) LOG_IF(FATAL, !(condition))
301 #define CHECK_EQ(x, y) CHECK((x) == (y))
302 #define CHECK_NE(x, y) CHECK((x) != (y))
303 #define CHECK_LT(x, y) CHECK((x) < (y))
304 #define CHECK_LE(x, y) CHECK((x) <= (y))
305 #define CHECK_GT(x, y) CHECK((x) > (y))
306 #define CHECK_GE(x, y) CHECK((x) >= (y))
308 #define UNREACHABLE() LOG(FATAL)
312 #define LOG_IF(severity, condition) \
316 #define VLOG(n) LOG(DEBUG##n)
371 #define DEBUG_TIMER(name) logger::DebugTimer(logger::INFO, __FILE__, __LINE__, name)
376 #define DEBUG_TIMER_NEW_THREAD(parent_thread_id) \
378 if (g_enable_debug_timer) \
379 logger::debug_timer_new_thread(parent_thread_id); \
384 #endif // SHARED_LOGGER_H
QidScopeGuard set_thread_local_query_id(QueryId const query_id)
void debug_timer_new_thread(ThreadId parent_thread_id)
std::unique_ptr< boost::program_options::options_description > options_
constexpr std::array< char const *, 3 > ChannelNames
std::set< Channel > Channels
std::string stopAndGetJson()
QidScopeGuard(QueryId const id)
std::unique_ptr< boost::log::record > record_
LogOptions(char const *argv0)
QidScopeGuard(QidScopeGuard &&that)
bool g_enable_debug_timer
boost::filesystem::path get_log_dir_path()
void set_once_fatal_func(FatalFunc fatal_func)
constexpr std::array< char, 3 > ChannelSymbols
QidScopeGuard & operator=(QidScopeGuard const &)=delete
void(*)() noexcept FatalFunc
constexpr std::array< char, 8 > SeveritySymbols
bool fast_logging_check(Channel)
void init(LogOptions const &log_opts)
Severity g_min_active_severity
#define OMINSCI_CHECKOP_FUNCTION(name, op)
BOOST_NOINLINE std::string * check_failed(X const &x, Y const &y, char const *xstr, char const *ystr, char const *op_str)
DebugTimer & operator=(DebugTimer const &)=delete
DebugTimer(DebugTimer const &)=delete
std::unique_ptr< boost::log::record_ostream > stream_
constexpr std::array< char const *, 8 > SeverityNames
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
std::ostream & operator<<(std::ostream &out, Channels const &channels)
QidScopeGuard & operator=(QidScopeGuard &&that)
boost::log::record_ostream & stream(char const *file, int line)
void parse_command_line(int, char const *const *)