From b2b8838bacf78d23c495fc3f6b64eb2f56910859 Mon Sep 17 00:00:00 2001 From: Helge Norberg Date: Wed, 16 Dec 2015 14:14:40 +0100 Subject: [PATCH] Added support for categorizing log into normal, call and communication. --- common/log.cpp | 2 ++ common/log.h | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/common/log.cpp b/common/log.cpp index 8ae7c35bb..d9e5ac898 100644 --- a/common/log.cpp +++ b/common/log.cpp @@ -151,6 +151,8 @@ void init() stream_backend->auto_flush(true); auto stream_sink = boost::make_shared(stream_backend); + // Never log calltrace to console. The terminal is too slow, so the log queue will build up faster than consumed. + stream_sink->set_filter(boost::log::expressions::attr("Channel") != log_category::call); bool print_all_characters = false; stream_sink->set_formatter(boost::bind(&my_formatter, print_all_characters, _1, _2)); diff --git a/common/log.h b/common/log.h index 3deb67f2f..e786a8b84 100644 --- a/common/log.h +++ b/common/log.h @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -65,16 +66,29 @@ inline std::basic_string replace_nonprintable_copy(std::basic_string add_preformatted_line_sink(std::function formatted_line_sink); -typedef boost::log::sources::wseverity_logger_mt caspar_logger; +enum class log_category +{ + normal, + call, + communication +}; + +typedef boost::log::sources::wseverity_channel_logger_mt caspar_logger; BOOST_LOG_INLINE_GLOBAL_LOGGER_INIT(logger, caspar_logger) { internal::init(); - return caspar_logger(boost::log::trivial::trace); + return caspar_logger( + boost::log::keywords::severity = boost::log::trivial::trace, + boost::log::keywords::channel = log_category::normal); } #define CASPAR_LOG(lvl)\ - BOOST_LOG_SEV(::caspar::log::logger::get(), ::boost::log::trivial::lvl) + BOOST_LOG_CHANNEL_SEV(::caspar::log::logger::get(), ::caspar::log::log_category::normal, ::boost::log::trivial::lvl) +#define CASPAR_LOG_CALL(lvl)\ + BOOST_LOG_CHANNEL_SEV(::caspar::log::logger::get(), ::caspar::log::log_category::call, ::boost::log::trivial::lvl) +#define CASPAR_LOG_COMMUNICATION(lvl)\ + BOOST_LOG_CHANNEL_SEV(::caspar::log::logger::get(), ::caspar::log::log_category::communication, ::boost::log::trivial::lvl) #define CASPAR_LOG_CALL_STACK() try{\ CASPAR_LOG(info) << L"callstack (" << caspar::get_thread_info().name << L"):\n" << caspar::get_call_stack();\ -- 2.39.2