]> git.sesse.net Git - casparcg/blobdiff - common/log.h
Write timestamp, thread and severity on each line in a multiline log statement, not...
[casparcg] / common / log.h
index 57495cad6e84c3ca3335805cdfe9cee78f5eb065..3deb67f2f4257ebc5d968e5951477717933156f0 100644 (file)
 
 #pragma once
 
+#include "os/stack_trace.h"
+#include "utf.h"
+#include "thread_info.h"
+
 #include <boost/log/trivial.hpp>
 #include <boost/log/sources/global_logger_storage.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 {
        
@@ -55,28 +63,7 @@ inline std::basic_string<T> replace_nonprintable_copy(std::basic_string<T, std::
 }
 
 void add_file_sink(const std::wstring& folder);
-
-/*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;
-}*/
+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;
 
@@ -90,16 +77,27 @@ BOOST_LOG_INLINE_GLOBAL_LOGGER_INIT(logger, caspar_logger)
        BOOST_LOG_SEV(::caspar::log::logger::get(), ::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 print_child(
+               boost::log::trivial::severity_level level,
+               const std::wstring& indent,
+               const std::wstring& elem,
+               const boost::property_tree::wptree& tree);
+
 }}