Skip to content

Commit

Permalink
Merge pull request #955 from SergiusTheBest/use-plog-utf8-converter
Browse files Browse the repository at this point in the history
Use plog::UTF8Converter instead of std::codecvt_utf8
  • Loading branch information
paullouisageneau authored Aug 26, 2023
2 parents be51f7e + fbc81a7 commit a3b2fce
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ if(WIN32)
if(MSVC)
add_definitions(-DNOMINMAX)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
endif()
endif()

Expand Down
1 change: 0 additions & 1 deletion Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ lib libdatachannel
<toolset>msvc:<define>WIN32_LEAN_AND_MEAN
<toolset>msvc:<define>NOMINMAX
<toolset>msvc:<define>_CRT_SECURE_NO_WARNINGS
<toolset>msvc:<define>_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
<library>/libdatachannel//usrsctp
<library>/libdatachannel//juice
<library>/libdatachannel//plog
Expand Down
18 changes: 4 additions & 14 deletions src/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include "plog/Appenders/ColorConsoleAppender.h"
#include "plog/Converters/UTF8Converter.h"
#include "plog/Formatters/FuncMessageFormatter.h"
#include "plog/Formatters/TxtFormatter.h"
#include "plog/Init.h"
Expand All @@ -19,11 +20,6 @@

#include <mutex>

#ifdef _WIN32
#include <codecvt>
#include <locale>
#endif

namespace {

void plogInit(plog::Severity severity, plog::IAppender *appender) {
Expand Down Expand Up @@ -58,16 +54,10 @@ struct LogAppender : public plog::IAppender {
auto formatted = plog::FuncMessageFormatter::format(record);
formatted.pop_back(); // remove newline

#ifdef _WIN32
using convert_type = std::codecvt_utf8<wchar_t>;
std::wstring_convert<convert_type, wchar_t> converter;
std::string str = converter.to_bytes(formatted);
#else
std::string str = formatted;
#endif
const auto& converted = plog::UTF8Converter::convert(formatted); // does nothing on non-Windows systems

if (!callback(static_cast<LogLevel>(severity), str))
std::cout << plog::severityToString(severity) << " " << str << std::endl;
if (!callback(static_cast<LogLevel>(severity), converted))
std::cout << plog::severityToString(severity) << " " << converted << std::endl;
}
};

Expand Down

0 comments on commit a3b2fce

Please sign in to comment.