X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Flog.h;h=9df9470f2f7f364d59b106ae4df8d35f03bf1b65;hb=62c7da66319a85de98331bcf9dded7490ab62884;hp=57495cad6e84c3ca3335805cdfe9cee78f5eb065;hpb=1f2344fe8705342b0503af4609064267e9ae42f4;p=casparcg diff --git a/common/log.h b/common/log.h index 57495cad6..9df9470f2 100644 --- a/common/log.h +++ b/common/log.h @@ -21,27 +21,41 @@ #pragma once +#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 { - + namespace internal{ void init(); std::wstring get_call_stack(); +std::string current_exception_diagnostic_information(); } +const char* remove_source_prefix(const char* file); + template inline void replace_nonprintable(std::basic_string, std::allocator>& str, T with) { std::locale loc; std::replace_if(str.begin(), str.end(), [&](T c)->bool { - return - (!std::isprint(c, loc) - && c != '\r' + return + (!std::isprint(c, loc) + && c != '\r' && c != '\n') || c > static_cast(127); }, with); @@ -54,52 +68,57 @@ inline std::basic_string replace_nonprintable_copy(std::basic_string add_preformatted_line_sink(std::function formatted_line_sink); -/*template< typename CharT, typename TraitsT > -inline std::basic_ostream< CharT, TraitsT >& operator<< ( - std::basic_ostream< CharT, TraitsT >& strm, severity_level lvl) +enum class log_category { - if(lvl == trace) - strm << "trace"; - else if(lvl == debug) - strm << "debug"; - else if(lvl == info) - strm << "info"; - else if(lvl == warning) - strm << "warning"; - else if(lvl == error) - strm << "error"; - else if(lvl == fatal) - strm << "fatal"; - else - strm << static_cast(lvl); - - return strm; -}*/ - -typedef boost::log::sources::wseverity_logger_mt caspar_logger; + 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:\n" << caspar::log::internal::get_call_stack();\ + CASPAR_LOG(info) << L"callstack (" << caspar::get_thread_info().name << L"):\n" << caspar::get_call_stack();\ }\ catch(...){} #define CASPAR_LOG_CURRENT_EXCEPTION() try{\ - CASPAR_LOG(error) << caspar::u16(boost::current_exception_diagnostic_information()) << L"Caught at:\n" << caspar::log::internal::get_call_stack();\ + CASPAR_LOG(error) << caspar::u16(::caspar::log::internal::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(::caspar::log::internal::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); +}}