]> git.sesse.net Git - casparcg/blob - common/log/log.h
2.0. audio_mixer: Optimized.
[casparcg] / common / log / log.h
1 /*\r
2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 *  This file is part of CasparCG.\r
5 *\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
10 *\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
15 \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
18 *\r
19 */\r
20 #pragma once\r
21 \r
22 #if defined(_MSC_VER)\r
23 #pragma warning (push)\r
24 #pragma warning (disable : 4100)\r
25 #pragma warning (disable : 4127) // conditional expression is constant\r
26 #pragma warning (disable : 4512)\r
27 #pragma warning (disable : 4714) // marked as __forceinline not inlined\r
28 #pragma warning (disable : 4996) // _CRT_SECURE_NO_WARNINGS\r
29 #endif\r
30 \r
31 #include <boost/log/detail/prologue.hpp>\r
32 #include <boost/log/keywords/severity.hpp>\r
33 #include <boost/log/sources/global_logger_storage.hpp>\r
34 #include <boost/log/sources/severity_logger.hpp>\r
35 #include <boost/log/sources/record_ostream.hpp>\r
36 \r
37 namespace caspar { namespace log {\r
38         \r
39 namespace internal{\r
40 void init();\r
41 }\r
42 \r
43 void add_file_sink(const std::wstring& folder);\r
44 \r
45 enum severity_level\r
46 {\r
47         trace,\r
48         debug,\r
49         info,\r
50         warning,\r
51         error,\r
52         fatal\r
53 };\r
54 \r
55 template< typename CharT, typename TraitsT >\r
56 inline std::basic_ostream< CharT, TraitsT >& operator<< (\r
57         std::basic_ostream< CharT, TraitsT >& strm, severity_level lvl)\r
58 {\r
59         if(lvl == trace)\r
60                 strm << "trace";\r
61         else if(lvl == debug)\r
62                 strm << "debug";\r
63         else if(lvl == info)\r
64                 strm << "info";\r
65         else if(lvl == warning)\r
66                 strm << "warning";\r
67         else if(lvl == error)\r
68                 strm << "error";\r
69         else if(lvl == fatal)\r
70                 strm << "fatal";\r
71         else\r
72                 strm << static_cast<int>(lvl);\r
73 \r
74         return strm;\r
75 }\r
76 \r
77 typedef boost::log::sources::wseverity_logger_mt<severity_level> caspar_logger;\r
78 \r
79 BOOST_LOG_DECLARE_GLOBAL_LOGGER_INIT(logger, caspar_logger)\r
80 {\r
81         internal::init();\r
82         return caspar_logger(boost::log::keywords::severity = trace);\r
83 }\r
84 \r
85 #define CASPAR_LOG(lvl)\\r
86         BOOST_LOG_STREAM_WITH_PARAMS(::caspar::log::get_logger(),\\r
87                 (::boost::log::keywords::severity = ::caspar::log::lvl))\r
88 \r
89 #define CASPAR_LOG_CURRENT_EXCEPTION() \\r
90         try\\r
91         {CASPAR_LOG(error) << boost::current_exception_diagnostic_information().c_str();}\\r
92         catch(...){}\r
93 \r
94 void set_log_level(const std::wstring& lvl);\r
95 \r
96 }}\r
97 \r
98 #if defined(_MSC_VER)\r
99 #pragma warning (pop)\r
100 #endif