diff --git a/CMakeLists.txt b/CMakeLists.txt index 20b21882..9f95fb58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -230,10 +230,8 @@ endif() # --------------------------------------------------------------------------------------- # Misc definitions according to tweak options # --------------------------------------------------------------------------------------- -set(SPDLOG_WCHAR_TO_UTF8_SUPPORT ${SPDLOG_WCHAR_SUPPORT}) foreach( SPDLOG_OPTION - SPDLOG_WCHAR_TO_UTF8_SUPPORT SPDLOG_WCHAR_FILENAMES SPDLOG_NO_EXCEPTIONS SPDLOG_CLOCK_COARSE diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 0a262eb2..dbd0dc7c 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -52,9 +52,6 @@ #if !defined(SPDLOG_USE_STD_FORMAT) && FMT_VERSION >= 80000 // backward compatibility with fmt versions older than 8 # define SPDLOG_FMT_RUNTIME(format_string) fmt::runtime(format_string) # define SPDLOG_FMT_STRING(format_string) FMT_STRING(format_string) -# if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) -# include -# endif #else # define SPDLOG_FMT_RUNTIME(format_string) format_string # define SPDLOG_FMT_STRING(format_string) format_string @@ -149,18 +146,6 @@ using format_string_t = std::string_view; template struct is_convertible_to_basic_format_string : std::integral_constant>::value> {}; - -# if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) -using wstring_view_t = std::wstring_view; -using wmemory_buf_t = std::wstring; - -template -# if __cpp_lib_format >= 202207L -using wformat_string_t = std::wformat_string; -# else -using wformat_string_t = std::wstring_view; -# endif -# endif # define SPDLOG_BUF_TO_STRING(x) x #else // use fmt lib instead of std::format namespace fmt_lib = fmt; @@ -189,7 +174,7 @@ struct is_convertible_to_basic_format_string std::is_convertible>::value || std::is_same, fmt_runtime_string>::value> {}; -# if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) +# if defined(SPDLOG_WCHAR_FILENAMES) using wstring_view_t = fmt::basic_string_view; using wmemory_buf_t = fmt::basic_memory_buffer; @@ -199,12 +184,6 @@ using wformat_string_t = fmt::wformat_string; # define SPDLOG_BUF_TO_STRING(x) fmt::to_string(x) #endif -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT -# ifndef _WIN32 -# error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows -# endif // _WIN32 -#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT - template struct is_convertible_to_any_format_string : std::integral_constant::value || is_convertible_to_basic_format_string::value> @@ -356,7 +335,7 @@ SPDLOG_CONSTEXPR_FUNC spdlog::string_view_t to_string_view(spdlog::string_view_t return str; } -#if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) +#if defined(SPDLOG_WCHAR_FILENAMES) SPDLOG_CONSTEXPR_FUNC spdlog::wstring_view_t to_string_view(const wmemory_buf_t &buf) SPDLOG_NOEXCEPT { return spdlog::wstring_view_t{buf.data(), buf.size()}; diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h index ea8864ea..02bc6daf 100644 --- a/include/spdlog/details/os-inl.h +++ b/include/spdlog/details/os-inl.h @@ -32,7 +32,7 @@ # include # endif -# if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES) +# if defined(SPDLOG_WCHAR_FILENAMES) # include # include # endif @@ -472,7 +472,7 @@ SPDLOG_INLINE bool in_terminal(FILE *file) SPDLOG_NOEXCEPT #endif } -#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32) +#if defined(SPDLOG_WCHAR_FILENAMES) && defined(_WIN32) SPDLOG_INLINE void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target) { if (wstr.size() > static_cast((std::numeric_limits::max)()) / 2 - 1) @@ -538,7 +538,7 @@ SPDLOG_INLINE void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) throw_spdlog_ex(fmt_lib::format("MultiByteToWideChar failed. Last error: {}", ::GetLastError())); } -#endif // (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32) +#endif // defined(SPDLOG_WCHAR_FILENAMES) && defined(_WIN32) // return true on success static SPDLOG_INLINE bool mkdir_(const filename_t &path) diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 37b00874..55067770 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -88,7 +88,7 @@ SPDLOG_API bool is_color_terminal() SPDLOG_NOEXCEPT; // Source: https://github.com/agauniyal/rang/ SPDLOG_API bool in_terminal(FILE *file) SPDLOG_NOEXCEPT; -#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32) +#if defined(SPDLOG_WCHAR_FILENAMES) && defined(_WIN32) SPDLOG_API void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target); SPDLOG_API void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target); diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 0802a5d9..6025a020 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -18,13 +18,6 @@ #include #include -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT -# ifndef _WIN32 -# error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows -# endif -# include -#endif - #include #ifndef SPDLOG_NO_EXCEPTIONS @@ -176,91 +169,6 @@ public: log(level::critical, fmt, std::forward(args)...); } -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT - template - void log(source_loc loc, level::level_enum lvl, wformat_string_t fmt, Args &&...args) - { - log_(loc, lvl, details::to_string_view(fmt), std::forward(args)...); - } - - template - void log(level::level_enum lvl, wformat_string_t fmt, Args &&...args) - { - log(source_loc{}, lvl, fmt, std::forward(args)...); - } - - void log(log_clock::time_point log_time, source_loc loc, level::level_enum lvl, wstring_view_t msg) - { - bool log_enabled = should_log(lvl); - bool traceback_enabled = tracer_.enabled(); - if (!log_enabled && !traceback_enabled) - { - return; - } - - memory_buf_t buf; - details::os::wstr_to_utf8buf(wstring_view_t(msg.data(), msg.size()), buf); - details::log_msg log_msg(log_time, loc, name_, lvl, string_view_t(buf.data(), buf.size())); - log_it_(log_msg, log_enabled, traceback_enabled); - } - - void log(source_loc loc, level::level_enum lvl, wstring_view_t msg) - { - bool log_enabled = should_log(lvl); - bool traceback_enabled = tracer_.enabled(); - if (!log_enabled && !traceback_enabled) - { - return; - } - - memory_buf_t buf; - details::os::wstr_to_utf8buf(wstring_view_t(msg.data(), msg.size()), buf); - details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size())); - log_it_(log_msg, log_enabled, traceback_enabled); - } - - void log(level::level_enum lvl, wstring_view_t msg) - { - log(source_loc{}, lvl, msg); - } - - template - void trace(wformat_string_t fmt, Args &&...args) - { - log(level::trace, fmt, std::forward(args)...); - } - - template - void debug(wformat_string_t fmt, Args &&...args) - { - log(level::debug, fmt, std::forward(args)...); - } - - template - void info(wformat_string_t fmt, Args &&...args) - { - log(level::info, fmt, std::forward(args)...); - } - - template - void warn(wformat_string_t fmt, Args &&...args) - { - log(level::warn, fmt, std::forward(args)...); - } - - template - void error(wformat_string_t fmt, Args &&...args) - { - log(level::err, fmt, std::forward(args)...); - } - - template - void critical(wformat_string_t fmt, Args &&...args) - { - log(level::critical, fmt, std::forward(args)...); - } -#endif - template void trace(const T &msg) { @@ -380,30 +288,6 @@ protected: SPDLOG_LOGGER_CATCH(loc) } -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT - template - void log_(source_loc loc, level::level_enum lvl, wstring_view_t fmt, Args &&...args) - { - bool log_enabled = should_log(lvl); - bool traceback_enabled = tracer_.enabled(); - if (!log_enabled && !traceback_enabled) - { - return; - } - SPDLOG_TRY - { - // format to wmemory_buffer and convert to utf8 - wmemory_buf_t wbuf; - fmt_lib::vformat_to(std::back_inserter(wbuf), fmt, fmt_lib::make_format_args(args...)); - - memory_buf_t buf; - details::os::wstr_to_utf8buf(wstring_view_t(wbuf.data(), wbuf.size()), buf); - details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size())); - log_it_(log_msg, log_enabled, traceback_enabled); - } - SPDLOG_LOGGER_CATCH(loc) - } -#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT // log the given message (if the given log level is high enough), // and save backtrace (if backtrace is enabled). diff --git a/include/spdlog/sinks/msvc_sink.h b/include/spdlog/sinks/msvc_sink.h index bf68ae88..8d52a2c5 100644 --- a/include/spdlog/sinks/msvc_sink.h +++ b/include/spdlog/sinks/msvc_sink.h @@ -6,20 +6,13 @@ #if defined(_WIN32) # include -# if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) -# include -# endif # include # include # include // Avoid including windows.h (https://stackoverflow.com/a/30741042) -# if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) -extern "C" __declspec(dllimport) void __stdcall OutputDebugStringW(const wchar_t *lpOutputString); -# else extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString); -# endif extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); namespace spdlog { @@ -45,13 +38,7 @@ protected: memory_buf_t formatted; base_sink::formatter_->format(msg, formatted); formatted.push_back('\0'); // add a null terminator for OutputDebugString -# if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) - wmemory_buf_t wformatted; - details::os::utf8_to_wstrbuf(string_view_t(formatted.data(), formatted.size()), wformatted); - OutputDebugStringW(wformatted.data()); -# else OutputDebugStringA(formatted.data()); -# endif } void flush_() override {} diff --git a/include/spdlog/sinks/win_eventlog_sink.h b/include/spdlog/sinks/win_eventlog_sink.h index d23d00a8..a269ebcc 100644 --- a/include/spdlog/sinks/win_eventlog_sink.h +++ b/include/spdlog/sinks/win_eventlog_sink.h @@ -236,18 +236,9 @@ protected: base_sink::formatter_->format(msg, formatted); formatted.push_back('\0'); -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT - wmemory_buf_t buf; - details::os::utf8_to_wstrbuf(string_view_t(formatted.data(), formatted.size()), buf); - - LPCWSTR lp_wstr = buf.data(); - succeeded = static_cast(::ReportEventW(event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg), - event_id_, current_user_sid_.as_sid(), 1, 0, &lp_wstr, nullptr)); -#else LPCSTR lp_str = formatted.data(); succeeded = static_cast(::ReportEventA(event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg), event_id_, current_user_sid_.as_sid(), 1, 0, &lp_str, nullptr)); -#endif if (!succeeded) { diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index fbfe5fb8..a43e7b2f 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -200,56 +200,6 @@ inline void log(level::level_enum lvl, const T &msg) default_logger_raw()->log(lvl, msg); } -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT -template -inline void log(source_loc source, level::level_enum lvl, wformat_string_t fmt, Args &&...args) -{ - default_logger_raw()->log(source, lvl, fmt, std::forward(args)...); -} - -template -inline void log(level::level_enum lvl, wformat_string_t fmt, Args &&...args) -{ - default_logger_raw()->log(source_loc{}, lvl, fmt, std::forward(args)...); -} - -template -inline void trace(wformat_string_t fmt, Args &&...args) -{ - default_logger_raw()->trace(fmt, std::forward(args)...); -} - -template -inline void debug(wformat_string_t fmt, Args &&...args) -{ - default_logger_raw()->debug(fmt, std::forward(args)...); -} - -template -inline void info(wformat_string_t fmt, Args &&...args) -{ - default_logger_raw()->info(fmt, std::forward(args)...); -} - -template -inline void warn(wformat_string_t fmt, Args &&...args) -{ - default_logger_raw()->warn(fmt, std::forward(args)...); -} - -template -inline void error(wformat_string_t fmt, Args &&...args) -{ - default_logger_raw()->error(fmt, std::forward(args)...); -} - -template -inline void critical(wformat_string_t fmt, Args &&...args) -{ - default_logger_raw()->critical(fmt, std::forward(args)...); -} -#endif - template inline void trace(const T &msg) { diff --git a/include/spdlog/tweakme.h b/include/spdlog/tweakme.h index 5bcb5ff4..b3ef0d68 100644 --- a/include/spdlog/tweakme.h +++ b/include/spdlog/tweakme.h @@ -87,12 +87,6 @@ // #define SPDLOG_USE_STD_FORMAT /////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to enable wchar_t support (convert to utf8) -// -// #define SPDLOG_WCHAR_TO_UTF8_SUPPORT -/////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////// // Uncomment to prevent child processes from inheriting log file descriptors // diff --git a/tests/test_stdout_api.cpp b/tests/test_stdout_api.cpp index d55223ff..c1f1578b 100644 --- a/tests/test_stdout_api.cpp +++ b/tests/test_stdout_api.cpp @@ -79,20 +79,3 @@ TEST_CASE("stderr_color_mt", "[stderr]") spdlog::drop_all(); } -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT - -TEST_CASE("wchar_api", "[stdout]") -{ - auto l = spdlog::stdout_logger_st("wchar_logger"); - l->set_pattern("%+"); - l->set_level(spdlog::level::trace); - l->trace(L"Test wchar_api"); - l->trace(L"Test wchar_api {}", L"param"); - l->trace(L"Test wchar_api {}", 1); - l->trace(L"Test wchar_api {}", std::wstring{L"wstring param"}); - l->trace(std::wstring{L"Test wchar_api wstring"}); - SPDLOG_LOGGER_DEBUG(l, L"Test SPDLOG_LOGGER_DEBUG {}", L"param"); - spdlog::drop_all(); -} - -#endif