X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Flog.h;h=94a67671edf78f7196378710d03f382ac0c9ff8e;hb=8c61df76c4b35ab58316f35b6a09a3f977efd596;hp=a013554534001fe79c8eb12d803d26a7f0265809;hpb=46d13b2c97abd753f2005209ed977abba0b53fd8;p=casparcg diff --git a/common/log.h b/common/log.h index a01355453..94a67671e 100644 --- a/common/log.h +++ b/common/log.h @@ -1,111 +1,131 @@ -/* -* Copyright (c) 2011 Sveriges Television AB -* -* This file is part of CasparCG (www.casparcg.com). -* -* CasparCG is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* CasparCG is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with CasparCG. If not, see . -* -* Author: Robert Nagy, ronag89@gmail.com -*/ - -#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 -#include -#include -#include -#include - -#include -#include - -namespace caspar { namespace log { - -namespace internal{ -void init(); -std::wstring get_call_stack(); -} - -void add_file_sink(const std::wstring& folder); - -enum severity_level -{ - trace, - debug, - info, - warning, - error, - fatal -}; - -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(lvl); - - return strm; -} - -typedef boost::log::sources::wseverity_logger_mt caspar_logger; - -BOOST_LOG_DECLARE_GLOBAL_LOGGER_INIT(logger, caspar_logger) -{ - internal::init(); - return caspar_logger(boost::log::keywords::severity = trace); -} - -#define CASPAR_LOG(lvl)\ - BOOST_LOG_STREAM_WITH_PARAMS(::caspar::log::get_logger(),\ - (::boost::log::keywords::severity = ::caspar::log::lvl)) - -#define CASPAR_LOG_CALL_STACK() try{\ - CASPAR_LOG(info) << L"callstack:\n" << caspar::log::internal::get_call_stack();\ - }\ - catch(...){} - -#define CASPAR_LOG_CURRENT_EXCEPTION() try{\ - CASPAR_LOG(error) << caspar::u16(boost::current_exception_diagnostic_information()) << L"callstack:\n" << caspar::log::internal::get_call_stack();\ - }\ - catch(...){} - -void set_log_level(const std::wstring& lvl); - -}} - -#if defined(_MSC_VER) -#pragma warning (pop) +/* +* Copyright (c) 2011 Sveriges Television AB +* +* This file is part of CasparCG (www.casparcg.com). +* +* CasparCG is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* CasparCG is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with CasparCG. If not, see . +* +* Author: Robert Nagy, ronag89@gmail.com +*/ + +#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 +#include +#include +#include +#include + +#include +#include + +namespace caspar { namespace log { + +namespace internal{ +void init(); +std::wstring get_call_stack(); +} + +template +inline void replace_nonprintable(std::basic_string, std::allocator>& str, T with) +{ + std::locale loc; + std::replace_if(str.begin(), str.end(), [&](T c)->bool { + return + (!std::isprint(c, loc) + && c != '\r' + && c != '\n') + || c > static_cast(127); + }, with); +} + +template +inline std::basic_string replace_nonprintable_copy(std::basic_string, std::allocator> str, T with) +{ + replace_nonprintable(str, with); + return str; +} + +void add_file_sink(const std::wstring& folder); + +enum severity_level +{ + trace, + debug, + info, + warning, + error, + fatal +}; + +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(lvl); + + return strm; +} + +typedef boost::log::sources::wseverity_logger_mt caspar_logger; + +BOOST_LOG_DECLARE_GLOBAL_LOGGER_INIT(logger, caspar_logger) +{ + internal::init(); + return caspar_logger(boost::log::keywords::severity = trace); +} + +#define CASPAR_LOG(lvl)\ + BOOST_LOG_STREAM_WITH_PARAMS(::caspar::log::get_logger(),\ + (::boost::log::keywords::severity = ::caspar::log::lvl)) + +#define CASPAR_LOG_CALL_STACK() try{\ + CASPAR_LOG(info) << L"callstack:\n" << caspar::log::internal::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();\ + }\ + catch(...){} + +void set_log_level(const std::wstring& lvl); + +}} + +#if defined(_MSC_VER) +#pragma warning (pop) #endif \ No newline at end of file