X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Flog.h;h=4cc983e4556f0b787a1c10df62f7bc28a17f352c;hb=61974506572c47b0650c4b5bfa65cd18621d5fec;hp=e9f57110fdfa93cbd9d4a7d0c088acf42c55a5c5;hpb=42dca5d749026fb72d0e0c4443978def8bb05079;p=casparcg diff --git a/common/log.h b/common/log.h index e9f57110f..4cc983e45 100644 --- a/common/log.h +++ b/common/log.h @@ -24,13 +24,19 @@ #include "os/stack_trace.h" #include "utf.h" #include "thread_info.h" +#include "enum_class.h" #include +#include #include +#include #include +#include #include #include +#include +#include namespace caspar { namespace log { @@ -59,18 +65,34 @@ 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 = 1, + calltrace = 2, + communication = 4 +}; +ENUM_ENABLE_BITWISE(log_category) +BOOST_LOG_ATTRIBUTE_KEYWORD(category, "Channel", ::caspar::log::log_category) + +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::calltrace, ::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();\ @@ -78,11 +100,23 @@ BOOST_LOG_INLINE_GLOBAL_LOGGER_INIT(logger, caspar_logger) catch(...){} #define CASPAR_LOG_CURRENT_EXCEPTION() try{\ - CASPAR_LOG(error) << caspar::u16(boost::current_exception_diagnostic_information()) << L"Caught at (" << caspar::get_thread_info().name << L"):\n" << caspar::get_call_stack();\ + CASPAR_LOG(error) << caspar::u16(boost::current_exception_diagnostic_information()) << L"Caught at (" << caspar::get_thread_info().name << L"):\n" << caspar::get_call_stack();\ }\ catch(...){} - + +#define CASPAR_LOG_CURRENT_EXCEPTION_AT_LEVEL(lvl) try{\ + CASPAR_LOG(lvl) << caspar::u16(boost::current_exception_diagnostic_information()) << L"Caught at (" << caspar::get_thread_info().name << L"):\n" << caspar::get_call_stack();\ + }\ + catch(...){} + void set_log_level(const std::wstring& lvl); +void set_log_category(const std::wstring& cat, bool enabled); + +void print_child( + boost::log::trivial::severity_level level, + const std::wstring& indent, + const std::wstring& elem, + const boost::property_tree::wptree& tree); }}