]> git.sesse.net Git - casparcg/commitdiff
Added support for categorizing log into normal, call and communication.
authorHelge Norberg <helge.norberg@svt.se>
Wed, 16 Dec 2015 13:14:40 +0000 (14:14 +0100)
committerHelge Norberg <helge.norberg@svt.se>
Wed, 16 Dec 2015 13:14:40 +0000 (14:14 +0100)
common/log.cpp
common/log.h

index 8ae7c35bba9221604aa13be32c8e2c9abfb89a15..d9e5ac89845069ff9458b910849847ec792812fd 100644 (file)
@@ -151,6 +151,8 @@ void init()
        stream_backend->auto_flush(true);
 
        auto stream_sink = boost::make_shared<stream_sink_type>(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<log_category>("Channel") != log_category::call);
 
        bool print_all_characters = false;
        stream_sink->set_formatter(boost::bind(&my_formatter<boost::log::wformatting_ostream>, print_all_characters, _1, _2));
index 3deb67f2f4257ebc5d968e5951477717933156f0..e786a8b84bf8b017804fe170cd634a6bd1b644c1 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <boost/log/trivial.hpp>
 #include <boost/log/sources/global_logger_storage.hpp>
+#include <boost/log/sources/severity_channel_logger.hpp>
 #include <boost/exception/all.hpp>
 #include <boost/property_tree/ptree_fwd.hpp>
 
@@ -65,16 +66,29 @@ inline std::basic_string<T> replace_nonprintable_copy(std::basic_string<T, std::
 void add_file_sink(const std::wstring& folder);
 std::shared_ptr<void> add_preformatted_line_sink(std::function<void(std::string line)> formatted_line_sink);
 
-typedef boost::log::sources::wseverity_logger_mt<boost::log::trivial::severity_level> caspar_logger;
+enum class log_category
+{
+       normal,
+       call,
+       communication
+};
+
+typedef boost::log::sources::wseverity_channel_logger_mt<boost::log::trivial::severity_level, log_category> 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();\