OmniSciDB  c07336695a
logger::Logger Class Reference

#include <Logger.h>

Public Member Functions

 Logger (Channel)
 
 Logger (Severity)
 
 Logger (Logger &&)=default
 
 ~Logger ()
 
 operator bool () const
 
boost::log::record_ostream & stream (char const *file, int line)
 

Private Attributes

bool const is_channel_
 
int const enum_value_
 
std::unique_ptr< boost::log::record > record_
 
std::unique_ptr< boost::log::record_ostream > stream_
 

Detailed Description

Definition at line 151 of file Logger.h.

Constructor & Destructor Documentation

◆ Logger() [1/3]

logger::Logger::Logger ( Channel  channel)

Definition at line 344 of file Logger.cpp.

References record_, and stream_.

345  : is_channel_(true)
346  , enum_value_(channel)
347  , record_(std::make_unique<boost::log::record>(
348  gChannelLogger::get().open_record(boost::log::keywords::channel = channel))) {
349  if (*record_) {
350  stream_ = std::make_unique<boost::log::record_ostream>(*record_);
351  }
352 }
int const enum_value_
Definition: Logger.h:153
std::unique_ptr< boost::log::record > record_
Definition: Logger.h:155
bool const is_channel_
Definition: Logger.h:152
std::unique_ptr< boost::log::record_ostream > stream_
Definition: Logger.h:156

◆ Logger() [2/3]

logger::Logger::Logger ( Severity  severity)

Definition at line 354 of file Logger.cpp.

References record_, and stream_.

355  : is_channel_(false)
356  , enum_value_(severity)
357  , record_(std::make_unique<boost::log::record>(gSeverityLogger::get().open_record(
358  boost::log::keywords::severity = severity))) {
359  if (*record_) {
360  stream_ = std::make_unique<boost::log::record_ostream>(*record_);
361  }
362 }
int const enum_value_
Definition: Logger.h:153
std::unique_ptr< boost::log::record > record_
Definition: Logger.h:155
bool const is_channel_
Definition: Logger.h:152
std::unique_ptr< boost::log::record_ostream > stream_
Definition: Logger.h:156

◆ Logger() [3/3]

logger::Logger::Logger ( Logger &&  )
default

◆ ~Logger()

logger::Logger::~Logger ( )

Definition at line 364 of file Logger.cpp.

References enum_value_, logger::FATAL, logger::g_fatal_func, logger::g_fatal_func_flag, is_channel_, and stream_.

364  {
365  if (stream_) {
366  if (is_channel_) {
367  gChannelLogger::get().push_record(boost::move(stream_->get_record()));
368  } else {
369  gSeverityLogger::get().push_record(boost::move(stream_->get_record()));
370  }
371  }
372  if (!is_channel_ && static_cast<Severity>(enum_value_) == Severity::FATAL) {
373  if (FatalFunc fatal_func = g_fatal_func.load()) {
374  // set_once_fatal_func() prevents race condition.
375  // Exceptions thrown by (*fatal_func)() are propagated here.
376  std::call_once(g_fatal_func_flag, *fatal_func);
377  }
378  abort();
379  }
380 }
int const enum_value_
Definition: Logger.h:153
std::once_flag g_fatal_func_flag
Definition: Logger.cpp:240
bool const is_channel_
Definition: Logger.h:152
std::atomic< FatalFunc > g_fatal_func
Definition: Logger.cpp:239
std::unique_ptr< boost::log::record_ostream > stream_
Definition: Logger.h:156
void(*)() FatalFunc
Definition: Logger.h:141

Member Function Documentation

◆ operator bool()

logger::Logger::operator bool ( ) const

Definition at line 382 of file Logger.cpp.

References stream_.

382  {
383  return static_cast<bool>(stream_);
384 }
std::unique_ptr< boost::log::record_ostream > stream_
Definition: Logger.h:156

◆ stream()

boost::log::record_ostream & logger::Logger::stream ( char const *  file,
int  line 
)

Definition at line 386 of file Logger.cpp.

References stream_.

386  {
387  return *stream_ << boost::filesystem::path(file).filename().native() << ':' << line
388  << ' ';
389 }
std::unique_ptr< boost::log::record_ostream > stream_
Definition: Logger.h:156

Member Data Documentation

◆ enum_value_

int const logger::Logger::enum_value_
private

Definition at line 153 of file Logger.h.

Referenced by ~Logger().

◆ is_channel_

bool const logger::Logger::is_channel_
private

Definition at line 152 of file Logger.h.

Referenced by ~Logger().

◆ record_

std::unique_ptr<boost::log::record> logger::Logger::record_
private

Definition at line 155 of file Logger.h.

Referenced by Logger().

◆ stream_

std::unique_ptr<boost::log::record_ostream> logger::Logger::stream_
private

Definition at line 156 of file Logger.h.

Referenced by Logger(), operator bool(), stream(), and ~Logger().


The documentation for this class was generated from the following files: