#pragma once
-#if defined(_MSC_VER)
-#pragma warning (push)
-#pragma warning (disable : 4100)
-#pragma warning (disable : 4127) // conditional expression is constant
-#pragma warning (disable : 4512)
-#pragma warning (disable : 4714) // marked as __forceinline not inlined
-#pragma warning (disable : 4996) // _CRT_SECURE_NO_WARNINGS
-#endif
-
-#include <boost/log/detail/prologue.hpp>
-#include <boost/log/keywords/severity.hpp>
+#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 <boost/log/sources/global_logger_storage.hpp>
-#include <boost/log/sources/severity_logger.hpp>
-#include <boost/log/sources/record_ostream.hpp>
+#include <boost/log/sources/severity_channel_logger.hpp>
+#include <boost/exception/all.hpp>
+#include <boost/property_tree/ptree_fwd.hpp>
#include <string>
#include <locale>
+#include <functional>
+#include <memory>
namespace caspar { namespace log {
return str;
}
-void add_file_sink(const std::wstring& folder);
+void add_file_sink(const std::wstring& file, const boost::log::filter& filter);
+std::shared_ptr<void> add_preformatted_line_sink(std::function<void(std::string line)> formatted_line_sink);
-enum severity_level
+enum class log_category
{
- trace,
- debug,
- info,
- warning,
- error,
- fatal
+ normal = 1,
+ calltrace = 2,
+ communication = 4
};
+ENUM_ENABLE_BITWISE(log_category)
+BOOST_LOG_ATTRIBUTE_KEYWORD(category, "Channel", ::caspar::log::log_category)
-template< typename CharT, typename TraitsT >
-inline std::basic_ostream< CharT, TraitsT >& operator<< (
- std::basic_ostream< CharT, TraitsT >& strm, severity_level lvl)
-{
- 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<int>(lvl);
-
- return strm;
-}
+typedef boost::log::sources::wseverity_channel_logger_mt<boost::log::trivial::severity_level, log_category> caspar_logger;
-typedef boost::log::sources::wseverity_logger_mt<severity_level> caspar_logger;
-
-BOOST_LOG_DECLARE_GLOBAL_LOGGER_INIT(logger, caspar_logger)
+BOOST_LOG_INLINE_GLOBAL_LOGGER_INIT(logger, caspar_logger)
{
internal::init();
- return caspar_logger(boost::log::keywords::severity = 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_STREAM_WITH_PARAMS(::caspar::log::get_logger(),\
- (::boost::log::keywords::severity = ::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::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(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);
}}
-#if defined(_MSC_VER)
-#pragma warning (pop)
-#endif
\ No newline at end of file