Skip to content

Commit

Permalink
Use plog::UTF8Converter instead of std::codecvt_utf8
Browse files Browse the repository at this point in the history
Plog has a built-in UTF-8 conversion, so `std::codecvt_utf8` is not required. This makes code simpler and gets rid of `std::codecvt_utf8` deprecation warnings. Also it fixes using a more recent plog version (>= 1.1.10) that supports utf8everywhere mode. That mode is triggered by the `/utf-8` switch in MSVC.
  • Loading branch information
SergiusTheBest committed Aug 25, 2023
1 parent be51f7e commit fbc81a7
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 fbc81a7

Please sign in to comment.