2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG (www.casparcg.com).
\r
6 * CasparCG is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * CasparCG is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
\r
19 * Author: Robert Nagy, ronag89@gmail.com
\r
24 #if defined(_MSC_VER)
\r
25 #pragma warning (push)
\r
26 #pragma warning (disable : 4100)
\r
27 #pragma warning (disable : 4127) // conditional expression is constant
\r
28 #pragma warning (disable : 4512)
\r
29 #pragma warning (disable : 4714) // marked as __forceinline not inlined
\r
30 #pragma warning (disable : 4996) // _CRT_SECURE_NO_WARNINGS
\r
33 #include <boost/log/detail/prologue.hpp>
\r
34 #include <boost/log/keywords/severity.hpp>
\r
35 #include <boost/log/sources/global_logger_storage.hpp>
\r
36 #include <boost/log/sources/severity_logger.hpp>
\r
37 #include <boost/log/sources/record_ostream.hpp>
\r
42 namespace caspar { namespace log {
\r
46 std::wstring get_call_stack();
\r
49 template<typename T>
\r
50 inline void replace_nonprintable(std::basic_string<T, std::char_traits<T>, std::allocator<T>>& str, T with)
\r
53 std::replace_if(str.begin(), str.end(), [&](T c)->bool {
\r
55 (!std::isprint(c, loc)
\r
58 || c > static_cast<T>(127);
\r
62 template<typename T>
\r
63 inline std::basic_string<T> replace_nonprintable_copy(std::basic_string<T, std::char_traits<T>, std::allocator<T>> str, T with)
\r
65 replace_nonprintable(str, with);
\r
69 void add_file_sink(const std::wstring& folder);
\r
81 template< typename CharT, typename TraitsT >
\r
82 inline std::basic_ostream< CharT, TraitsT >& operator<< (
\r
83 std::basic_ostream< CharT, TraitsT >& strm, severity_level lvl)
\r
87 else if(lvl == debug)
\r
89 else if(lvl == info)
\r
91 else if(lvl == warning)
\r
93 else if(lvl == error)
\r
95 else if(lvl == fatal)
\r
98 strm << static_cast<int>(lvl);
\r
103 typedef boost::log::sources::wseverity_logger_mt<severity_level> caspar_logger;
\r
105 BOOST_LOG_DECLARE_GLOBAL_LOGGER_INIT(logger, caspar_logger)
\r
108 return caspar_logger(boost::log::keywords::severity = trace);
\r
111 #define CASPAR_LOG(lvl)\
\r
112 BOOST_LOG_STREAM_WITH_PARAMS(::caspar::log::get_logger(),\
\r
113 (::boost::log::keywords::severity = ::caspar::log::lvl))
\r
115 #define CASPAR_LOG_CALL_STACK() try{\
\r
116 CASPAR_LOG(info) << L"callstack:\n" << caspar::log::internal::get_call_stack();\
\r
120 #define CASPAR_LOG_CURRENT_EXCEPTION() try{\
\r
121 CASPAR_LOG(error) << caspar::u16(boost::current_exception_diagnostic_information()) << L"Caught at:\n" << caspar::log::internal::get_call_stack();\
\r
125 void set_log_level(const std::wstring& lvl);
\r
129 #if defined(_MSC_VER)
\r
130 #pragma warning (pop)
\r