OmniSciDB  5ade3759e0
logger Namespace Reference

Classes

class  Logger
 
class  LogOptions
 
struct  LogShutdown
 

Typedefs

using ClogSync = sinks::synchronous_sink< sinks::text_ostream_backend >
 
using FileSync = sinks::synchronous_sink< sinks::text_file_backend >
 
using Channels = std::set< Channel >
 
using FatalFunc = void(*)()
 
using ChannelLogger = boost::log::sources::channel_logger_mt< Channel >
 
using SeverityLogger = boost::log::sources::severity_logger_mt< Severity >
 

Enumerations

enum  Channel { IR = 0, PTX, _NCHANNELS }
 
enum  Severity {
  DEBUG4 = 0, DEBUG3, DEBUG2, DEBUG1,
  INFO, WARNING, ERROR, FATAL,
  _NSEVERITIES
}
 

Functions

template<typename TAG >
std::string replace_braces (std::string const &str, TAG const tag)
 
boost::log::attributes::current_process_id::value_type::native_type get_native_process_id (boost::log::value_ref< boost::log::attributes::current_process_id::value_type, tag::process_id > const &pid)
 
template<typename SINK >
sinks::text_file_backend::open_handler_type create_or_replace_symlink (boost::weak_ptr< SINK > weak_ptr, std::string &&symlink)
 
boost::log::formatting_ostream & operator<< (boost::log::formatting_ostream &strm, boost::log::to_log_manip< Channel, tag::channel > const &manip)
 
boost::log::formatting_ostream & operator<< (boost::log::formatting_ostream &strm, boost::log::to_log_manip< Severity, tag::severity > const &manip)
 
template<typename TAG , typename SINK >
void set_formatter (SINK &sink)
 
template<typename FILE_SINK , typename TAG >
boost::shared_ptr< FILE_SINK > make_sink (LogOptions const &log_opts, boost::filesystem::path const &full_log_dir, TAG const tag)
 
template<typename CONSOLE_SINK >
boost::shared_ptr< CONSOLE_SINK > make_sink (LogOptions const &log_opts)
 
void init (LogOptions const &log_opts)
 
void set_once_fatal_func (FatalFunc fatal_func)
 
void shutdown ()
 
std::istream & operator>> (std::istream &in, Channels &channels)
 
std::ostream & operator<< (std::ostream &out, Channels const &channels)
 
std::istream & operator>> (std::istream &in, Severity &sev)
 
std::ostream & operator<< (std::ostream &out, Severity const &sev)
 
bool fast_logging_check (Channel)
 
bool fast_logging_check (Severity severity)
 
template<typename X , typename Y >
BOOST_NOINLINE std::string * check_failed (X const &x, Y const &y, char const *xstr, char const *ystr, char const *op_str)
 

Variables

std::atomic< FatalFuncg_fatal_func {nullptr}
 
std::once_flag g_fatal_func_flag
 
bool g_any_active_channels {false}
 
Severity g_min_active_severity {Severity::FATAL}
 
constexpr std::array< char const *, 2 > ChannelNames {"IR", "PTX"}
 
constexpr std::array< char, 2 > ChannelSymbols {'R', 'P'}
 
constexpr std::array< char const *, 8 > SeverityNames
 
constexpr std::array< char, 8 > SeveritySymbols {'4', '3', '2', '1', 'I', 'W', 'E', 'F'}
 

Typedef Documentation

◆ ChannelLogger

using logger::ChannelLogger = typedef boost::log::sources::channel_logger_mt<Channel>

Definition at line 144 of file Logger.h.

◆ Channels

using logger::Channels = typedef std::set<Channel>

Definition at line 100 of file Logger.h.

◆ ClogSync

using logger::ClogSync = typedef sinks::synchronous_sink<sinks::text_ostream_backend>

Definition at line 242 of file Logger.cpp.

◆ FatalFunc

using logger::FatalFunc = typedef void (*)()

Definition at line 141 of file Logger.h.

◆ FileSync

using logger::FileSync = typedef sinks::synchronous_sink<sinks::text_file_backend>

Definition at line 243 of file Logger.cpp.

◆ SeverityLogger

using logger::SeverityLogger = typedef boost::log::sources::severity_logger_mt<Severity>

Definition at line 147 of file Logger.h.

Enumeration Type Documentation

◆ Channel

Enumerator
IR 
PTX 
_NCHANNELS 

Definition at line 58 of file Logger.h.

◆ Severity

Enumerator
DEBUG4 
DEBUG3 
DEBUG2 
DEBUG1 
INFO 
WARNING 
ERROR 
FATAL 
_NSEVERITIES 

Definition at line 70 of file Logger.h.

70  {
71  DEBUG4 = 0,
72  DEBUG3,
73  DEBUG2,
74  DEBUG1,
75  INFO,
76  WARNING,
77  ERROR,
78  FATAL,
79  _NSEVERITIES // number of severity levels
80 };

Function Documentation

◆ check_failed()

template<typename X , typename Y >
BOOST_NOINLINE std::string* logger::check_failed ( X const &  x,
Y const &  y,
char const *  xstr,
char const *  ystr,
char const *  op_str 
)

Definition at line 203 of file Logger.h.

207  {
208  std::stringstream ss;
209  ss << "Check failed: " << xstr << op_str << ystr << " (" << x << op_str << y << ") ";
210  return new std::string(ss.str()); // Deleted by CHECK_OP macro.
211 }

◆ create_or_replace_symlink()

template<typename SINK >
sinks::text_file_backend::open_handler_type logger::create_or_replace_symlink ( boost::weak_ptr< SINK >  weak_ptr,
std::string &&  symlink 
)

Definition at line 149 of file Logger.cpp.

References error_code.

Referenced by make_sink().

151  {
152  namespace fs = boost::filesystem;
153  return [weak_ptr,
154  symlink = std::move(symlink)](sinks::text_file_backend::stream_type& stream) {
155  if (boost::shared_ptr<SINK> sink = weak_ptr.lock()) {
157  fs::path const& file_name = sink->locked_backend()->get_current_file_name();
158  fs::path const symlink_path = file_name.parent_path() / symlink;
159  fs::remove(symlink_path, ec);
160  if (ec) {
161  stream << fs::path(__FILE__).filename().native() << ':' << __LINE__ << ' '
162  << ec.message() << std::endl;
163  }
164  fs::create_symlink(file_name.filename(), symlink_path, ec);
165  if (ec) {
166  stream << fs::path(__FILE__).filename().native() << ':' << __LINE__ << ' '
167  << ec.message() << std::endl;
168  }
169  }
170  };
171 }
const int8_t const int64_t const uint64_t const int32_t const int64_t int64_t uint32_t const int64_t int32_t * error_code
+ Here is the caller graph for this function:

◆ fast_logging_check() [1/2]

bool logger::fast_logging_check ( Channel  )
inline

Definition at line 168 of file Logger.h.

References g_any_active_channels.

Referenced by LogSession::stdlog().

168  {
169  extern bool g_any_active_channels;
170  return g_any_active_channels;
171 }
bool g_any_active_channels
Definition: Logger.cpp:257
+ Here is the caller graph for this function:

◆ fast_logging_check() [2/2]

bool logger::fast_logging_check ( Severity  severity)
inline

Definition at line 173 of file Logger.h.

References g_min_active_severity.

173  {
175  return g_min_active_severity <= severity;
176 }
Severity g_min_active_severity
Definition: Logger.cpp:258
Severity
Definition: Logger.h:70

◆ get_native_process_id()

boost::log::attributes::current_process_id::value_type::native_type logger::get_native_process_id ( boost::log::value_ref< boost::log::attributes::current_process_id::value_type, tag::process_id > const &  pid)

Definition at line 142 of file Logger.cpp.

Referenced by set_formatter().

144  {
145  return pid ? pid->native_id() : 0;
146 }
+ Here is the caller graph for this function:

◆ init()

void logger::init ( LogOptions const &  log_opts)

Definition at line 260 of file Logger.cpp.

References _NSEVERITIES, logger::LogOptions::channels_, logger::LogOptions::full_log_dir(), g_any_active_channels, g_min_active_severity, INFO, run-benchmark-import::level, LOG, logger::LogOptions::max_files_, logger::LogOptions::severity_, and logger::LogOptions::severity_clog_.

Referenced by Importer_NS::Detector::Detector(), Calcite::get_session_prefix(), File_Namespace::FileMgr::getFileInfoForFileId(), Importer_NS::Loader::getReplicating(), QueryRunner::QueryRunner::init(), TestHelpers::init_logger_stderr_only(), File_Namespace::GlobalFileMgr::isAllocationCapped(), Importer_NS::Loader::Loader(), main(), ColumnarResults::mergeResults(), MapDProgramOptions::parse_command_line(), ResultSetManager::reduce(), and Executor::reduceMultiDeviceResultSets().

260  {
261  boost::shared_ptr<boost::log::core> core = boost::log::core::get();
262  // boost::log::add_common_attributes(); // LineID TimeStamp ProcessID ThreadID
263  core->add_global_attribute("TimeStamp", attr::local_clock());
264  core->add_global_attribute("ProcessID", attr::current_process_id());
265  if (0 < log_opts.max_files_) {
266  boost::filesystem::path const full_log_dir = log_opts.full_log_dir();
267  bool const log_dir_was_created = boost::filesystem::create_directory(full_log_dir);
268  // Don't create separate log sinks for anything less than Severity::INFO.
269  Severity const min_sink_level = std::max(Severity::INFO, log_opts.severity_);
270  for (int i = min_sink_level; i < Severity::_NSEVERITIES; ++i) {
271  Severity const level = static_cast<Severity>(i);
272  core->add_sink(make_sink<FileSync>(log_opts, full_log_dir, level));
273  }
274  g_min_active_severity = std::min(g_min_active_severity, log_opts.severity_);
275  if (log_dir_was_created) {
276  LOG(INFO) << "Log directory(" << full_log_dir.native() << ") created.";
277  }
278  for (auto const channel : log_opts.channels_) {
279  core->add_sink(make_sink<FileSync>(log_opts, full_log_dir, channel));
280  }
281  g_any_active_channels = !log_opts.channels_.empty();
282  }
283  core->add_sink(make_sink<ClogSync>(log_opts));
284  g_min_active_severity = std::min(g_min_active_severity, log_opts.severity_clog_);
285 }
#define LOG(tag)
Definition: Logger.h:182
Severity g_min_active_severity
Definition: Logger.cpp:258
Severity
Definition: Logger.h:70
bool g_any_active_channels
Definition: Logger.cpp:257
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_sink() [1/2]

template<typename FILE_SINK , typename TAG >
boost::shared_ptr<FILE_SINK> logger::make_sink ( LogOptions const &  log_opts,
boost::filesystem::path const &  full_log_dir,
TAG const  tag 
)

Definition at line 205 of file Logger.cpp.

References logger::LogOptions::auto_flush_, create_or_replace_symlink(), logger::LogOptions::file_name_pattern_, INFO, logger::LogOptions::max_files_, logger::LogOptions::min_free_space_, replace_braces(), logger::LogOptions::rotate_daily_, logger::LogOptions::rotation_size_, logger::LogOptions::severity_, and logger::LogOptions::symlink_.

207  {
208  auto sink = boost::make_shared<FILE_SINK>(
209  keywords::file_name =
210  full_log_dir / replace_braces(log_opts.file_name_pattern_, tag),
211  keywords::auto_flush = log_opts.auto_flush_,
212  keywords::rotation_size = log_opts.rotation_size_);
213  if /*constexpr*/ (std::is_same<TAG, Channel>::value) {
214  sink->set_filter(channel == static_cast<Channel>(tag));
215  set_formatter<Channel>(sink);
216  } else {
217  // INFO sink logs all other levels. Other sinks only log at their level or higher.
218  Severity const min_filter_level = static_cast<Severity>(tag) == Severity::INFO
219  ? log_opts.severity_
220  : static_cast<Severity>(tag);
221  sink->set_filter(min_filter_level <= severity);
222  set_formatter<Severity>(sink);
223  }
224  typename FILE_SINK::locked_backend_ptr backend = sink->locked_backend();
225  if (log_opts.rotate_daily_) {
226  backend->set_time_based_rotation(sinks::file::rotation_at_time_point(0, 0, 0));
227  }
228  backend->set_file_collector(
229  sinks::file::make_collector(keywords::target = full_log_dir,
230  keywords::max_files = log_opts.max_files_,
231  keywords::min_free_space = log_opts.min_free_space_));
232  backend->set_open_handler(create_or_replace_symlink(
233  boost::weak_ptr<FILE_SINK>(sink), replace_braces(log_opts.symlink_, tag)));
234  backend->scan_for_files();
235  return sink;
236 }
std::string replace_braces(std::string const &str, TAG const tag)
Definition: Logger.cpp:131
sinks::text_file_backend::open_handler_type create_or_replace_symlink(boost::weak_ptr< SINK > weak_ptr, std::string &&symlink)
Definition: Logger.cpp:149
Severity
Definition: Logger.h:70
+ Here is the call graph for this function:

◆ make_sink() [2/2]

template<typename CONSOLE_SINK >
boost::shared_ptr<CONSOLE_SINK> logger::make_sink ( LogOptions const &  log_opts)

Definition at line 246 of file Logger.cpp.

References logger::LogOptions::severity_clog_.

246  {
247  auto sink = boost::make_shared<CONSOLE_SINK>();
248  boost::shared_ptr<std::ostream> clog(&std::clog, boost::null_deleter());
249  sink->locked_backend()->add_stream(clog);
250  sink->set_filter(log_opts.severity_clog_ <= severity);
251  set_formatter<Severity>(sink);
252  return sink;
253 }

◆ operator<<() [1/4]

boost::log::formatting_ostream& logger::operator<< ( boost::log::formatting_ostream &  strm,
boost::log::to_log_manip< Channel, tag::channel > const &  manip 
)

Definition at line 173 of file Logger.cpp.

References ChannelSymbols.

175  {
176  return strm << ChannelSymbols[manip.get()];
177 }
constexpr std::array< char, 2 > ChannelSymbols
Definition: Logger.h:62

◆ operator<<() [2/4]

boost::log::formatting_ostream& logger::operator<< ( boost::log::formatting_ostream &  strm,
boost::log::to_log_manip< Severity, tag::severity > const &  manip 
)

Definition at line 179 of file Logger.cpp.

References SeveritySymbols.

181  {
182  return strm << SeveritySymbols[manip.get()];
183 }
constexpr std::array< char, 8 > SeveritySymbols
Definition: Logger.h:91

◆ operator<<() [3/4]

std::ostream& logger::operator<< ( std::ostream &  out,
Channels const &  channels 
)

Definition at line 318 of file Logger.cpp.

References ChannelNames, and out.

318  {
319  int i = 0;
320  for (auto const channel : channels) {
321  out << (i++ ? " " : "") << ChannelNames.at(channel);
322  }
323  return out;
324 }
constexpr std::array< char const *, 2 > ChannelNames
Definition: Logger.h:60
const int8_t const int64_t const uint64_t const int32_t const int64_t int64_t ** out

◆ operator<<() [4/4]

std::ostream& logger::operator<< ( std::ostream &  out,
Severity const &  sev 
)

Definition at line 340 of file Logger.cpp.

References SeverityNames.

340  {
341  return out << SeverityNames.at(sev);
342 }
constexpr std::array< char const *, 8 > SeverityNames
Definition: Logger.h:82
const int8_t const int64_t const uint64_t const int32_t const int64_t int64_t ** out

◆ operator>>() [1/2]

std::istream& logger::operator>> ( std::istream &  in,
Channels channels 
)

Definition at line 299 of file Logger.cpp.

References ChannelNames.

299  {
300  std::string line;
301  std::getline(in, line);
302  std::regex const rex(R"(\w+)");
303  using TokenItr = std::regex_token_iterator<std::string::iterator>;
304  TokenItr const end;
305  for (TokenItr tok(line.begin(), line.end(), rex); tok != end; ++tok) {
306  auto itr = std::find(ChannelNames.cbegin(), ChannelNames.cend(), *tok);
307  if (itr == ChannelNames.cend()) {
308  in.setstate(std::ios_base::failbit);
309  break;
310  } else {
311  channels.emplace(static_cast<Channel>(itr - ChannelNames.cbegin()));
312  }
313  }
314  return in;
315 }
constexpr std::array< char const *, 2 > ChannelNames
Definition: Logger.h:60

◆ operator>>() [2/2]

std::istream& logger::operator>> ( std::istream &  in,
Severity sev 
)

Definition at line 327 of file Logger.cpp.

References SeverityNames.

327  {
328  std::string token;
329  in >> token;
330  auto itr = std::find(SeverityNames.cbegin(), SeverityNames.cend(), token);
331  if (itr == SeverityNames.cend()) {
332  in.setstate(std::ios_base::failbit);
333  } else {
334  sev = static_cast<Severity>(itr - SeverityNames.cbegin());
335  }
336  return in;
337 }
Severity
Definition: Logger.h:70
constexpr std::array< char const *, 8 > SeverityNames
Definition: Logger.h:82

◆ replace_braces()

template<typename TAG >
std::string logger::replace_braces ( std::string const &  str,
TAG const  tag 
)

Definition at line 131 of file Logger.cpp.

References ChannelNames, and SeverityNames.

Referenced by make_sink().

131  {
132  constexpr std::regex::flag_type flags = std::regex::ECMAScript | std::regex::optimize;
133  static std::regex const regex(R"(\{SEVERITY\})", flags);
134  if /*constexpr*/ (std::is_same<TAG, Channel>::value) {
135  return std::regex_replace(str, regex, ChannelNames[tag]);
136  } else {
137  return std::regex_replace(str, regex, SeverityNames[tag]);
138  }
139 }
constexpr std::array< char const *, 8 > SeverityNames
Definition: Logger.h:82
constexpr std::array< char const *, 2 > ChannelNames
Definition: Logger.h:60
+ Here is the caller graph for this function:

◆ set_formatter()

template<typename TAG , typename SINK >
void logger::set_formatter ( SINK &  sink)

Definition at line 186 of file Logger.cpp.

References get_native_process_id().

186  {
187  if /*constexpr*/ (std::is_same<TAG, Channel>::value) {
188  sink->set_formatter(
189  expr::stream << expr::format_date_time<boost::posix_time::ptime>(
190  "TimeStamp", "%Y-%m-%dT%H:%M:%S.%f")
191  << ' ' << channel << ' '
192  << boost::phoenix::bind(&get_native_process_id, process_id.or_none())
193  << ' ' << expr::smessage);
194  } else {
195  sink->set_formatter(
196  expr::stream << expr::format_date_time<boost::posix_time::ptime>(
197  "TimeStamp", "%Y-%m-%dT%H:%M:%S.%f")
198  << ' ' << severity << ' '
199  << boost::phoenix::bind(&get_native_process_id, process_id.or_none())
200  << ' ' << expr::smessage);
201  }
202 }
boost::log::attributes::current_process_id::value_type::native_type get_native_process_id(boost::log::value_ref< boost::log::attributes::current_process_id::value_type, tag::process_id > const &pid)
Definition: Logger.cpp:142
+ Here is the call graph for this function:

◆ set_once_fatal_func()

void logger::set_once_fatal_func ( FatalFunc  fatal_func)

Definition at line 287 of file Logger.cpp.

References g_fatal_func.

Referenced by QueryRunner::QueryRunner::QueryRunner().

287  {
288  if (g_fatal_func.exchange(fatal_func)) {
289  throw std::runtime_error(
290  "logger::set_once_fatal_func() should not be called more than once.");
291  }
292 }
std::atomic< FatalFunc > g_fatal_func
Definition: Logger.cpp:239
+ Here is the caller graph for this function:

◆ shutdown()

void logger::shutdown ( )

Definition at line 294 of file Logger.cpp.

Referenced by heartbeat(), main(), anonymous_namespace{QueryRunner.cpp}::mapd_signal_handler(), MapDHandler::max_bytes_for_thrift(), and logger::LogShutdown::~LogShutdown().

294  {
295  boost::log::core::get()->remove_all_sinks();
296 }
+ Here is the caller graph for this function:

Variable Documentation

◆ ChannelNames

constexpr std::array<char const*, 2> logger::ChannelNames {"IR", "PTX"}

Definition at line 60 of file Logger.h.

Referenced by logger::LogOptions::LogOptions(), operator<<(), operator>>(), and replace_braces().

◆ ChannelSymbols

constexpr std::array<char, 2> logger::ChannelSymbols {'R', 'P'}

Definition at line 62 of file Logger.h.

Referenced by operator<<().

◆ g_any_active_channels

bool logger::g_any_active_channels {false}

Definition at line 257 of file Logger.cpp.

Referenced by fast_logging_check(), and init().

◆ g_fatal_func

std::atomic<FatalFunc> logger::g_fatal_func {nullptr}

Definition at line 239 of file Logger.cpp.

Referenced by set_once_fatal_func(), and logger::Logger::~Logger().

◆ g_fatal_func_flag

std::once_flag logger::g_fatal_func_flag

Definition at line 240 of file Logger.cpp.

Referenced by logger::Logger::~Logger().

◆ g_min_active_severity

Severity logger::g_min_active_severity {Severity::FATAL}

Definition at line 258 of file Logger.cpp.

Referenced by fast_logging_check(), and init().

◆ SeverityNames

constexpr std::array<char const*, 8> logger::SeverityNames
Initial value:
{"DEBUG4",
"DEBUG3",
"DEBUG2",
"DEBUG1",
"INFO",
"WARNING",
"ERROR",
"FATAL"}

Definition at line 82 of file Logger.h.

Referenced by logger::LogOptions::LogOptions(), operator<<(), operator>>(), and replace_braces().

◆ SeveritySymbols

constexpr std::array<char, 8> logger::SeveritySymbols {'4', '3', '2', '1', 'I', 'W', 'E', 'F'}

Definition at line 91 of file Logger.h.

Referenced by operator<<().