Skip to content

Commit

Permalink
Fix Logger Channels fusion.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpulver authored and andrewseidl committed Aug 5, 2021
1 parent d110c97 commit d2feb86
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
33 changes: 28 additions & 5 deletions Logger/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ BOOST_LOG_ATTRIBUTE_KEYWORD(process_id, "ProcessID", attr::current_process_id::v
BOOST_LOG_ATTRIBUTE_KEYWORD(channel, "Channel", Channel)
BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", Severity)

BOOST_LOG_GLOBAL_LOGGER_DEFAULT(gChannelLogger, ChannelLogger)
BOOST_LOG_GLOBAL_LOGGER_CTOR_ARGS(gChannelLogger_IR,
ChannelLogger,
(keywords::channel = IR))
BOOST_LOG_GLOBAL_LOGGER_CTOR_ARGS(gChannelLogger_PTX,
ChannelLogger,
(keywords::channel = PTX))
BOOST_LOG_GLOBAL_LOGGER_CTOR_ARGS(gChannelLogger_ASM,
ChannelLogger,
(keywords::channel = ASM))
BOOST_LOG_GLOBAL_LOGGER_DEFAULT(gSeverityLogger, SeverityLogger)

// Return last component of path
Expand Down Expand Up @@ -384,11 +392,25 @@ std::ostream& operator<<(std::ostream& out, Severity const& sev) {
return out << SeverityNames.at(sev);
}

namespace {
ChannelLogger& get_channel_logger(Channel const channel) {
switch (channel) {
default:
case IR:
return gChannelLogger_IR::get();
case PTX:
return gChannelLogger_PTX::get();
case ASM:
return gChannelLogger_ASM::get();
}
}
} // namespace

Logger::Logger(Channel channel)
: is_channel_(true)
, enum_value_(channel)
, record_(std::make_unique<boost::log::record>(
gChannelLogger::get().open_record(boost::log::keywords::channel = channel))) {
get_channel_logger(channel).open_record())) {
if (*record_) {
stream_ = std::make_unique<boost::log::record_ostream>(*record_);
}
Expand All @@ -397,8 +419,8 @@ Logger::Logger(Channel channel)
Logger::Logger(Severity severity)
: is_channel_(false)
, enum_value_(severity)
, record_(std::make_unique<boost::log::record>(gSeverityLogger::get().open_record(
boost::log::keywords::severity = severity))) {
, record_(std::make_unique<boost::log::record>(
gSeverityLogger::get().open_record(keywords::severity = severity))) {
if (*record_) {
stream_ = std::make_unique<boost::log::record_ostream>(*record_);
}
Expand All @@ -407,7 +429,8 @@ Logger::Logger(Severity severity)
Logger::~Logger() {
if (stream_) {
if (is_channel_) {
gChannelLogger::get().push_record(boost::move(stream_->get_record()));
get_channel_logger(static_cast<Channel>(enum_value_))
.push_record(boost::move(stream_->get_record()));
} else {
gSeverityLogger::get().push_record(boost::move(stream_->get_record()));
}
Expand Down
9 changes: 6 additions & 3 deletions Logger/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ extern bool g_enable_debug_timer;
namespace logger {

// Channel, ChannelNames, and ChannelSymbols must be updated together.
// Each Channel has its own ChannelLogger declared below and defined in Logger.cpp.
enum Channel { IR = 0, PTX, ASM, _NCHANNELS };

constexpr std::array<char const*, 3> ChannelNames{"IR", "PTX", "ASM"};
Expand Down Expand Up @@ -154,7 +155,9 @@ using FatalFunc = void (*)() noexcept;
void set_once_fatal_func(FatalFunc);

using ChannelLogger = boost::log::sources::channel_logger_mt<Channel>;
BOOST_LOG_GLOBAL_LOGGER(gChannelLogger, ChannelLogger)
BOOST_LOG_GLOBAL_LOGGER(gChannelLogger_IR, ChannelLogger)
BOOST_LOG_GLOBAL_LOGGER(gChannelLogger_PTX, ChannelLogger)
BOOST_LOG_GLOBAL_LOGGER(gChannelLogger_ASM, ChannelLogger)

using SeverityLogger = boost::log::sources::severity_logger_mt<Severity>;
BOOST_LOG_GLOBAL_LOGGER(gSeverityLogger, SeverityLogger)
Expand All @@ -168,8 +171,8 @@ class Logger {
std::unique_ptr<boost::log::record_ostream> stream_;

public:
Logger(Channel);
Logger(Severity);
explicit Logger(Channel);
explicit Logger(Severity);
Logger(Logger&&) = default;
~Logger();
operator bool() const;
Expand Down

0 comments on commit d2feb86

Please sign in to comment.