From ff8425f00ec870dec6ab0db2a8059fed3f4ce646 Mon Sep 17 00:00:00 2001 From: hellgore Date: Thu, 14 Jun 2012 17:31:18 +0000 Subject: [PATCH 1/1] Merged from trunk git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.1.0@3115 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d --- common/log.cpp | 30 +++++++++++--------------- common/log.h | 20 +++++++++++++++++ protocol/amcp/AMCPProtocolStrategy.cpp | 2 +- protocol/cii/CIIProtocolStrategy.cpp | 2 +- protocol/util/ClientInfo.h | 4 +++- shell/main.cpp | 11 ++++++++++ 6 files changed, 48 insertions(+), 21 deletions(-) diff --git a/common/log.cpp b/common/log.cpp index 8c055d652..f47e2a996 100644 --- a/common/log.cpp +++ b/common/log.cpp @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -72,21 +73,7 @@ namespace caspar { namespace log { using namespace boost; -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'; }, with); -} - -template -inline std::basic_string replace_nonprintable_copy(std::basic_string, std::allocator> str, T with) -{ - replace_nonprintable(str, with); - return str; -} - -void my_formatter(std::wostream& strm, boost::log::basic_record const& rec) +void my_formatter(bool print_all_characters, std::wostream& strm, boost::log::basic_record const& rec) { namespace lambda = boost::lambda; @@ -113,7 +100,14 @@ void my_formatter(std::wostream& strm, boost::log::basic_record const& strm << L" "; } - strm << replace_nonprintable_copy(rec.message(), L'?'); + if (print_all_characters) + { + strm << rec.message(); + } + else + { + strm << replace_nonprintable_copy(rec.message(), L'?'); + } } namespace internal{ @@ -139,7 +133,7 @@ void init() // stream_sink->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= debug); //#endif - stream_sink->locked_backend()->set_formatter(&my_formatter); + stream_sink->locked_backend()->set_formatter(boost::bind(my_formatter, false, _1, _2)); boost::log::wcore::get()->add_sink(stream_sink); } @@ -209,7 +203,7 @@ void add_file_sink(const std::wstring& folder) boost::log::keywords::open_mode = std::ios::app ); - file_sink->locked_backend()->set_formatter(&my_formatter); + file_sink->locked_backend()->set_formatter(boost::bind(my_formatter, true, _1, _2)); //#ifdef NDEBUG // file_sink->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= debug); diff --git a/common/log.h b/common/log.h index eb6dfbef4..2b2dd13a4 100644 --- a/common/log.h +++ b/common/log.h @@ -46,6 +46,26 @@ 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 diff --git a/protocol/amcp/AMCPProtocolStrategy.cpp b/protocol/amcp/AMCPProtocolStrategy.cpp index caf440e29..c4d02f7c4 100644 --- a/protocol/amcp/AMCPProtocolStrategy.cpp +++ b/protocol/amcp/AMCPProtocolStrategy.cpp @@ -112,7 +112,7 @@ void AMCPProtocolStrategy::Parse(const TCHAR* pData, int charCount, ClientInfoPt void AMCPProtocolStrategy::ProcessMessage(const std::wstring& message, ClientInfoPtr& pClientInfo) { - CASPAR_LOG(info) << L"Received message from " << pClientInfo->print() << ": " << message + L"\\r\\n"; + CASPAR_LOG(info) << L"Received message from " << pClientInfo->print() << ": " << message << L"\\r\\n"; bool bError = true; MessageParserState state = New; diff --git a/protocol/cii/CIIProtocolStrategy.cpp b/protocol/cii/CIIProtocolStrategy.cpp index bf312cb16..46c8d337e 100644 --- a/protocol/cii/CIIProtocolStrategy.cpp +++ b/protocol/cii/CIIProtocolStrategy.cpp @@ -85,7 +85,7 @@ void CIIProtocolStrategy::Parse(const TCHAR* pData, int charCount, IO::ClientInf void CIIProtocolStrategy::ProcessMessage(const std::wstring& message, IO::ClientInfoPtr pClientInfo) { - CASPAR_LOG(info) << L"Received message from " << pClientInfo->print() << ": " << message + L"\\r\\n"; + CASPAR_LOG(info) << L"Received message from " << pClientInfo->print() << ": " << message << L"\\r\\n"; std::vector tokens; int tokenCount = TokenizeMessage(message, &tokens); diff --git a/protocol/util/ClientInfo.h b/protocol/util/ClientInfo.h index c7fd4285d..0b6412ffa 100644 --- a/protocol/util/ClientInfo.h +++ b/protocol/util/ClientInfo.h @@ -25,6 +25,8 @@ #include #include +#include + namespace caspar { namespace IO { class ClientInfo @@ -47,7 +49,7 @@ struct ConsoleClientInfo : public caspar::IO::ClientInfo { void Send(const std::wstring& data) { - std::wcout << (L"#" + data); + std::wcout << (L"#" + caspar::log::replace_nonprintable_copy(data, L'?')); } void Disconnect(){} virtual std::wstring print() const {return L"Console";} diff --git a/shell/main.cpp b/shell/main.cpp index f9e827305..6f07d1d17 100644 --- a/shell/main.cpp +++ b/shell/main.cpp @@ -65,6 +65,7 @@ #include #include #include +#include #include @@ -83,6 +84,14 @@ void change_icon( const HICON hNewIcon ) ::FreeLibrary(hMod); } +void setup_global_locale() +{ + boost::locale::generator gen; + gen.categories(boost::locale::codepage_facet); + + std::locale::global(gen("")); +} + void setup_console_window() { auto hOut = GetStdHandle(STD_OUTPUT_HANDLE); @@ -279,6 +288,8 @@ int main(int argc, wchar_t* argv[]) SetUnhandledExceptionFilter(UserUnhandledExceptionFilter); signal(SIGABRT, on_abort); + setup_global_locale(); + std::wcout << L"Type \"q\" to close application." << std::endl; // Set debug mode. -- 2.39.5