]> git.sesse.net Git - casparcg/blobdiff - common/log.h
[bluefish_consumer] Install GPF handler for custom thread.
[casparcg] / common / log.h
index a4415c60f801253f03a5cd1853b60c8a183123bb..9df9470f2f7f364d59b106ae4df8d35f03bf1b65 100644 (file)
@@ -24,6 +24,7 @@
 #include "os/stack_trace.h"
 #include "utf.h"
 #include "thread_info.h"
+#include "enum_class.h"
 
 #include <boost/log/trivial.hpp>
 #include <boost/log/expressions.hpp>
 #include <memory>
 
 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<typename T>
 inline void replace_nonprintable(std::basic_string<T, std::char_traits<T>, std::allocator<T>>& 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<T>(127);
        }, with);
@@ -69,10 +73,11 @@ std::shared_ptr<void> add_preformatted_line_sink(std::function<void(std::string
 
 enum class log_category
 {
-       normal,
-       call,
-       communication
+       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<boost::log::trivial::severity_level, log_category> caspar_logger;
@@ -88,7 +93,7 @@ BOOST_LOG_INLINE_GLOBAL_LOGGER_INIT(logger, caspar_logger)
 #define CASPAR_LOG(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)
+       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)
 
@@ -98,16 +103,17 @@ 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(::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(boost::current_exception_diagnostic_information()) << L"Caught at (" << caspar::get_thread_info().name << L"):\n" << caspar::get_call_stack();\
+               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,
@@ -116,4 +122,3 @@ void print_child(
                const boost::property_tree::wptree& tree);
 
 }}
-