diff --git a/.gitignore b/.gitignore index fafa874a..cf0563ad 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,9 @@ build/* # Codelite .codelite +# KDevelop +*.kdev4 + # .orig files *.orig @@ -46,6 +49,7 @@ example/* !example/example.sln !example/example.vcxproj !example/CMakeLists.txt +!example/meson.build !example/multisink.cpp !example/jni diff --git a/.travis.yml b/.travis.yml index eb53e714..ddf03015 100644 --- a/.travis.yml +++ b/.travis.yml @@ -97,9 +97,9 @@ script: -DSPDLOG_BUILD_EXAMPLE_HO=ON \ -DSPDLOG_BUILD_BENCH=OFF \ -DSPDLOG_BUILD_TESTS=ON \ - -DSPDLOG_BUILD_TESTS_HO=ON \ - -DSPDLOG_SANITIZE_ADDRESS=$ASAN \ - -DSPDLOG_SANITIZE_THREAD=$TSAN + -DSPDLOG_BUILD_TESTS_HO=OFf \ + -DSPDLOG_SANITIZE_ADDRESS=$ASAN + - make VERBOSE=1 -j2 - ctest -j2 --output-on-failure diff --git a/README.md b/README.md index 0e59e2ed..ba06160a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Very fast, header-only/compiled, C++ logging library. [![Build Status](https://t #### Static lib version (recommended - much faster compile times, v1.4.0) * Copy [src/spdlog.cpp](https://github.com/gabime/spdlog/blob/v1.x/src/spdlog.cpp) to your build tree and pass the `-DSPDLOG_COMPILED_LIB` to the compiler. -* Or use CMake to build and use. See [example](https://github.com/gabime/spdlog/blob/v1.x/example/CMakeLists.txt). +* Or use **CMake** to build and use. See [example](https://github.com/gabime/spdlog/blob/v1.x/example/CMakeLists.txt). ## Platforms diff --git a/appveyor.yml b/appveyor.yml index 731c82a4..33c5d271 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -26,7 +26,7 @@ build_script: set PATH=C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin;%PATH% - cmake .. -G %GENERATOR% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DSPDLOG_BUILD_EXAMPLE=ON -DSPDLOG_BUILD_EXAMPLE_HO=ON -DSPDLOG_BUILD_TESTS=ON -DSPDLOG_BUILD_TESTS_HO=ON + cmake .. -G %GENERATOR% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DSPDLOG_BUILD_EXAMPLE=ON -DSPDLOG_BUILD_EXAMPLE_HO=ON -DSPDLOG_BUILD_TESTS=ON -DSPDLOG_BUILD_TESTS_HO=OFF cmake --build . --config %BUILD_TYPE% diff --git a/bench/meson.build b/bench/meson.build new file mode 100644 index 00000000..e185e689 --- /dev/null +++ b/bench/meson.build @@ -0,0 +1,13 @@ +benchmark = dependency('benchmark') + +bench_matrix = [ + ['bench', [spdlog_dep], []], + ['async_bench', [spdlog_dep], []], + ['formatter-bench', [spdlog_dep, benchmark], ['all']], + ['latency', [spdlog_dep, benchmark], []], +] + +foreach i : bench_matrix + bench_exe = executable(i[0], i[0] + '.cpp', dependencies: i[1]) + benchmark('bench_' + i[0], bench_exe, args: i[2]) +endforeach diff --git a/cygwin/CPackConfig.cmake b/cygwin/CPackConfig.cmake deleted file mode 100644 index 13833133..00000000 --- a/cygwin/CPackConfig.cmake +++ /dev/null @@ -1,82 +0,0 @@ -# This file will be configured to contain variables for CPack. These variables -# should be set in the CMake list file of the project before CPack module is -# included. The list of available CPACK_xxx variables and their associated -# documentation may be obtained using -# cpack --help-variable-list -# -# Some variables are common to all generators (e.g. CPACK_PACKAGE_NAME) -# and some are specific to a generator -# (e.g. CPACK_NSIS_EXTRA_INSTALL_COMMANDS). The generator specific variables -# usually begin with CPACK__xxxx. - - -SET(CPACK_BINARY_7Z "") -SET(CPACK_BINARY_BUNDLE "") -SET(CPACK_BINARY_CYGWIN "") -SET(CPACK_BINARY_DEB "") -SET(CPACK_BINARY_DRAGNDROP "") -SET(CPACK_BINARY_IFW "") -SET(CPACK_BINARY_NSIS "") -SET(CPACK_BINARY_OSXX11 "") -SET(CPACK_BINARY_PACKAGEMAKER "") -SET(CPACK_BINARY_RPM "") -SET(CPACK_BINARY_STGZ "") -SET(CPACK_BINARY_TBZ2 "") -SET(CPACK_BINARY_TGZ "") -SET(CPACK_BINARY_TXZ "") -SET(CPACK_BINARY_TZ "") -SET(CPACK_BINARY_WIX "") -SET(CPACK_BINARY_ZIP "") -SET(CPACK_CMAKE_GENERATOR "Unix Makefiles") -SET(CPACK_COMPONENT_UNSPECIFIED_HIDDEN "TRUE") -SET(CPACK_COMPONENT_UNSPECIFIED_REQUIRED "TRUE") -SET(CPACK_GENERATOR "TGZ;ZIP") -SET(CPACK_INCLUDE_TOPLEVEL_DIRECTORY "0") -SET(CPACK_INSTALL_CMAKE_PROJECTS "/cygdrive/e/devel/spdlog/cygwin;spdlog;ALL;.") -SET(CPACK_INSTALL_PREFIX "/usr/local") -SET(CPACK_MODULE_PATH "") -SET(CPACK_NSIS_DISPLAY_NAME "spdlog 1.4.0") -SET(CPACK_NSIS_INSTALLER_ICON_CODE "") -SET(CPACK_NSIS_INSTALLER_MUI_ICON_CODE "") -SET(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES") -SET(CPACK_NSIS_PACKAGE_NAME "spdlog 1.4.0") -SET(CPACK_OUTPUT_CONFIG_FILE "/cygdrive/e/devel/spdlog/cygwin/CPackConfig.cmake") -SET(CPACK_PACKAGE_CONTACT "Gabi Melman ") -SET(CPACK_PACKAGE_DEFAULT_LOCATION "/") -SET(CPACK_PACKAGE_DESCRIPTION_FILE "/usr/share/cmake-3.6.2/Templates/CPack.GenericDescription.txt") -SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "spdlog built using CMake") -SET(CPACK_PACKAGE_FILE_NAME "spdlog-1.4.0-CYGWIN") -SET(CPACK_PACKAGE_INSTALL_DIRECTORY "spdlog 1.4.0") -SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "spdlog 1.4.0") -SET(CPACK_PACKAGE_NAME "spdlog") -SET(CPACK_PACKAGE_RELOCATABLE "true") -SET(CPACK_PACKAGE_VENDOR "Gabi Melman") -SET(CPACK_PACKAGE_VERSION "1.4.0") -SET(CPACK_PACKAGE_VERSION_MAJOR "1") -SET(CPACK_PACKAGE_VERSION_MINOR "4") -SET(CPACK_PACKAGE_VERSION_PATCH "0") -SET(CPACK_PROJECT_URL "https://github.com/gabime/spdlog") -SET(CPACK_RESOURCE_FILE_LICENSE "/usr/share/cmake-3.6.2/Templates/CPack.GenericLicense.txt") -SET(CPACK_RESOURCE_FILE_README "/usr/share/cmake-3.6.2/Templates/CPack.GenericDescription.txt") -SET(CPACK_RESOURCE_FILE_WELCOME "/usr/share/cmake-3.6.2/Templates/CPack.GenericWelcome.txt") -SET(CPACK_SET_DESTDIR "OFF") -SET(CPACK_SOURCE_7Z "") -SET(CPACK_SOURCE_CYGWIN "ON") -SET(CPACK_SOURCE_GENERATOR "CygwinSource") -SET(CPACK_SOURCE_OUTPUT_CONFIG_FILE "/cygdrive/e/devel/spdlog/cygwin/CPackSourceConfig.cmake") -SET(CPACK_SOURCE_TBZ2 "") -SET(CPACK_SOURCE_TGZ "") -SET(CPACK_SOURCE_TXZ "") -SET(CPACK_SOURCE_TZ "") -SET(CPACK_SOURCE_ZIP "") -SET(CPACK_SYSTEM_NAME "CYGWIN") -SET(CPACK_TOPLEVEL_TAG "CYGWIN") -SET(CPACK_WIX_SIZEOF_VOID_P "8") - -if(NOT CPACK_PROPERTIES_FILE) - set(CPACK_PROPERTIES_FILE "/cygdrive/e/devel/spdlog/cygwin/CPackProperties.cmake") -endif() - -if(EXISTS ${CPACK_PROPERTIES_FILE}) - include(${CPACK_PROPERTIES_FILE}) -endif() diff --git a/cygwin/CPackSourceConfig.cmake b/cygwin/CPackSourceConfig.cmake deleted file mode 100644 index 6b869677..00000000 --- a/cygwin/CPackSourceConfig.cmake +++ /dev/null @@ -1,89 +0,0 @@ -# This file will be configured to contain variables for CPack. These variables -# should be set in the CMake list file of the project before CPack module is -# included. The list of available CPACK_xxx variables and their associated -# documentation may be obtained using -# cpack --help-variable-list -# -# Some variables are common to all generators (e.g. CPACK_PACKAGE_NAME) -# and some are specific to a generator -# (e.g. CPACK_NSIS_EXTRA_INSTALL_COMMANDS). The generator specific variables -# usually begin with CPACK__xxxx. - - -SET(CPACK_BINARY_7Z "") -SET(CPACK_BINARY_BUNDLE "") -SET(CPACK_BINARY_CYGWIN "") -SET(CPACK_BINARY_DEB "") -SET(CPACK_BINARY_DRAGNDROP "") -SET(CPACK_BINARY_IFW "") -SET(CPACK_BINARY_NSIS "") -SET(CPACK_BINARY_OSXX11 "") -SET(CPACK_BINARY_PACKAGEMAKER "") -SET(CPACK_BINARY_RPM "") -SET(CPACK_BINARY_STGZ "") -SET(CPACK_BINARY_TBZ2 "") -SET(CPACK_BINARY_TGZ "") -SET(CPACK_BINARY_TXZ "") -SET(CPACK_BINARY_TZ "") -SET(CPACK_BINARY_WIX "") -SET(CPACK_BINARY_ZIP "") -SET(CPACK_CMAKE_GENERATOR "Unix Makefiles") -SET(CPACK_COMPONENT_UNSPECIFIED_HIDDEN "TRUE") -SET(CPACK_COMPONENT_UNSPECIFIED_REQUIRED "TRUE") -SET(CPACK_GENERATOR "CygwinSource") -SET(CPACK_IGNORE_FILES "/CVS/;/\\.svn/;/\\.bzr/;/\\.hg/;/\\.git/;\\.swp\$;\\.#;/#") -SET(CPACK_INCLUDE_TOPLEVEL_DIRECTORY "0") -SET(CPACK_INSTALLED_DIRECTORIES "/cygdrive/e/devel/spdlog;/") -SET(CPACK_INSTALL_CMAKE_PROJECTS "") -SET(CPACK_INSTALL_PREFIX "/usr/local") -SET(CPACK_MODULE_PATH "") -SET(CPACK_NSIS_DISPLAY_NAME "spdlog 1.4.0") -SET(CPACK_NSIS_INSTALLER_ICON_CODE "") -SET(CPACK_NSIS_INSTALLER_MUI_ICON_CODE "") -SET(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES") -SET(CPACK_NSIS_PACKAGE_NAME "spdlog 1.4.0") -SET(CPACK_OUTPUT_CONFIG_FILE "/cygdrive/e/devel/spdlog/cygwin/CPackConfig.cmake") -SET(CPACK_PACKAGE_CONTACT "Gabi Melman ") -SET(CPACK_PACKAGE_DEFAULT_LOCATION "/") -SET(CPACK_PACKAGE_DESCRIPTION_FILE "/usr/share/cmake-3.6.2/Templates/CPack.GenericDescription.txt") -SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "spdlog built using CMake") -SET(CPACK_PACKAGE_FILE_NAME "spdlog-1.4.0-Source") -SET(CPACK_PACKAGE_INSTALL_DIRECTORY "spdlog 1.4.0") -SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "spdlog 1.4.0") -SET(CPACK_PACKAGE_NAME "spdlog") -SET(CPACK_PACKAGE_RELOCATABLE "true") -SET(CPACK_PACKAGE_VENDOR "Gabi Melman") -SET(CPACK_PACKAGE_VERSION "1.4.0") -SET(CPACK_PACKAGE_VERSION_MAJOR "1") -SET(CPACK_PACKAGE_VERSION_MINOR "4") -SET(CPACK_PACKAGE_VERSION_PATCH "0") -SET(CPACK_PROJECT_URL "https://github.com/gabime/spdlog") -SET(CPACK_RESOURCE_FILE_LICENSE "/usr/share/cmake-3.6.2/Templates/CPack.GenericLicense.txt") -SET(CPACK_RESOURCE_FILE_README "/usr/share/cmake-3.6.2/Templates/CPack.GenericDescription.txt") -SET(CPACK_RESOURCE_FILE_WELCOME "/usr/share/cmake-3.6.2/Templates/CPack.GenericWelcome.txt") -SET(CPACK_SET_DESTDIR "OFF") -SET(CPACK_SOURCE_7Z "") -SET(CPACK_SOURCE_CYGWIN "ON") -SET(CPACK_SOURCE_GENERATOR "CygwinSource") -SET(CPACK_SOURCE_IGNORE_FILES "/CVS/;/\\.svn/;/\\.bzr/;/\\.hg/;/\\.git/;\\.swp\$;\\.#;/#") -SET(CPACK_SOURCE_INSTALLED_DIRECTORIES "/cygdrive/e/devel/spdlog;/") -SET(CPACK_SOURCE_OUTPUT_CONFIG_FILE "/cygdrive/e/devel/spdlog/cygwin/CPackSourceConfig.cmake") -SET(CPACK_SOURCE_PACKAGE_FILE_NAME "spdlog-1.4.0-Source") -SET(CPACK_SOURCE_TBZ2 "") -SET(CPACK_SOURCE_TGZ "") -SET(CPACK_SOURCE_TOPLEVEL_TAG "CYGWIN-Source") -SET(CPACK_SOURCE_TXZ "") -SET(CPACK_SOURCE_TZ "") -SET(CPACK_SOURCE_ZIP "") -SET(CPACK_STRIP_FILES "") -SET(CPACK_SYSTEM_NAME "CYGWIN") -SET(CPACK_TOPLEVEL_TAG "CYGWIN-Source") -SET(CPACK_WIX_SIZEOF_VOID_P "8") - -if(NOT CPACK_PROPERTIES_FILE) - set(CPACK_PROPERTIES_FILE "/cygdrive/e/devel/spdlog/cygwin/CPackProperties.cmake") -endif() - -if(EXISTS ${CPACK_PROPERTIES_FILE}) - include(${CPACK_PROPERTIES_FILE}) -endif() diff --git a/cygwin/spdlogConfig.cmake b/cygwin/spdlogConfig.cmake deleted file mode 100644 index 6cdd5446..00000000 --- a/cygwin/spdlogConfig.cmake +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright(c) 2019 spdlog authors -# Distributed under the MIT License (http://opensource.org/licenses/MIT) - -find_package(Threads REQUIRED) - -set(SPDLOG_FMT_EXTERNAL OFF) -set(config_targets_file spdlogConfigTargets.cmake) - -if(SPDLOG_FMT_EXTERNAL) - include(CMakeFindDependencyMacro) - find_dependency(fmt CONFIG) -endif() - - -include("${CMAKE_CURRENT_LIST_DIR}/${config_targets_file}") diff --git a/cygwin/spdlogConfigVersion.cmake b/cygwin/spdlogConfigVersion.cmake deleted file mode 100644 index 66f87f7e..00000000 --- a/cygwin/spdlogConfigVersion.cmake +++ /dev/null @@ -1,46 +0,0 @@ -# This is a basic version file for the Config-mode of find_package(). -# It is used by write_basic_package_version_file() as input file for configure_file() -# to create a version-file which can be installed along a config.cmake file. -# -# The created file sets PACKAGE_VERSION_EXACT if the current version string and -# the requested version string are exactly the same and it sets -# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version, -# but only if the requested major version is the same as the current one. -# The variable CVF_VERSION must be set before calling configure_file(). - - -set(PACKAGE_VERSION "1.4.0") - -if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) - set(PACKAGE_VERSION_COMPATIBLE FALSE) -else() - - if("1.4.0" MATCHES "^([0-9]+)\\.") - set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}") - else() - set(CVF_VERSION_MAJOR "1.4.0") - endif() - - if(PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR) - set(PACKAGE_VERSION_COMPATIBLE TRUE) - else() - set(PACKAGE_VERSION_COMPATIBLE FALSE) - endif() - - if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) - set(PACKAGE_VERSION_EXACT TRUE) - endif() -endif() - - -# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it: -if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "8" STREQUAL "") - return() -endif() - -# check that the installed version has the same 32/64bit-ness as the one which is currently searching: -if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "8") - math(EXPR installedBits "8 * 8") - set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)") - set(PACKAGE_VERSION_UNSUITABLE TRUE) -endif() diff --git a/example/meson.build b/example/meson.build new file mode 100644 index 00000000..0a5a53c7 --- /dev/null +++ b/example/meson.build @@ -0,0 +1,8 @@ +example_matrix = [ + ['spdlog-example', spdlog_dep], + ['spdlog-example-ho', spdlog_headeronly_dep], +] + +foreach i : example_matrix + test_exe = executable(i[0], ['example.cpp'], dependencies: i[1]) +endforeach diff --git a/include/spdlog/common.h b/include/spdlog/common.h index ae9f0fa4..2f23e9e4 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -26,11 +26,6 @@ #include #endif //_WIN32 -#if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) -#include -#include -#endif - #ifdef SPDLOG_COMPILED_LIB #undef SPDLOG_HEADER_ONLY #define SPDLOG_INLINE @@ -80,11 +75,6 @@ class sink; #if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) using filename_t = std::wstring; #define SPDLOG_FILENAME_T(s) L##s -inline std::string filename_to_str(const filename_t &filename) -{ - std::wstring_convert, wchar_t> c; - return c.to_bytes(filename); -} #else using filename_t = std::string; #define SPDLOG_FILENAME_T(s) s @@ -97,10 +87,13 @@ using err_handler = std::function; // string_view type - either std::string_view or fmt::string_view (pre c++17) #if defined(FMT_USE_STD_STRING_VIEW) -using string_view_t = std::string_view; +template +using basic_string_view_t = std::basic_string_view; #else -using string_view_t = fmt::string_view; +template +using basic_string_view_t = fmt::basic_string_view; #endif +using string_view_t = basic_string_view_t; #if defined(SPDLOG_NO_ATOMIC_LEVELS) using level_t = details::null_atomic_int; diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h index e0809d9b..0675436b 100644 --- a/include/spdlog/details/os-inl.h +++ b/include/spdlog/details/os-inl.h @@ -36,6 +36,10 @@ #include #endif +#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES) +#include +#endif + #else // unix #include @@ -342,13 +346,14 @@ SPDLOG_INLINE void sleep_for_millis(int milliseconds) SPDLOG_NOEXCEPT // wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined) #if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) -SPDLOG_INLINE std::string filename_to_str(const filename_t &filename) SPDLOG_NOEXCEPT +SPDLOG_INLINE std::string filename_to_str(const filename_t &filename) { - std::wstring_convert, wchar_t> c; - return c.to_bytes(filename); + fmt::memory_buffer buf; + wstr_to_utf8buf(filename, buf); + return fmt::to_string(buf); } #else -SPDLOG_INLINE std::string filename_to_str(const filename_t &filename) SPDLOG_NOEXCEPT +SPDLOG_INLINE std::string filename_to_str(const filename_t &filename) { return filename; } @@ -398,28 +403,42 @@ SPDLOG_INLINE bool in_terminal(FILE *file) SPDLOG_NOEXCEPT #endif } -#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) && defined(_WIN32) -SPDLOG_INLINE void wbuf_to_utf8buf(const fmt::wmemory_buffer &wbuf, fmt::memory_buffer &target) +#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32) +SPDLOG_INLINE void wstr_to_utf8buf(basic_string_view_t wstr, fmt::memory_buffer &target) { - int wbuf_size = static_cast(wbuf.size()); - if (wbuf_size == 0) + if (wstr.size() > static_cast(std::numeric_limits::max())) { + throw spdlog::spdlog_ex("UTF-16 string is too big to be converted to UTF-8"); + } + + int wstr_size = static_cast(wstr.size()); + if (wstr_size == 0) + { + target.resize(0); return; } - auto result_size = ::WideCharToMultiByte(CP_UTF8, 0, wbuf.data(), wbuf_size, NULL, 0, NULL, NULL); + int result_size = static_cast(target.capacity()); + if ((wstr_size + 1) * 2 > result_size) + { + result_size = ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size, NULL, 0, NULL, NULL); + } if (result_size > 0) { target.resize(result_size); - ::WideCharToMultiByte(CP_UTF8, 0, wbuf.data(), wbuf_size, &target.data()[0], result_size, NULL, NULL); - } - else - { - throw spdlog::spdlog_ex(fmt::format("WideCharToMultiByte failed. Last error: {}", ::GetLastError())); + result_size = ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size, target.data(), result_size, NULL, NULL); + + if (result_size > 0) + { + target.resize(result_size); + return; + } } + + throw spdlog::spdlog_ex(fmt::format("WideCharToMultiByte failed. Last error: {}", ::GetLastError())); } -#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT) && _WIN32 +#endif // (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32) } // namespace os } // namespace details diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 4afe0cb9..27694494 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -68,7 +68,7 @@ size_t thread_id() SPDLOG_NOEXCEPT; // See https://github.com/gabime/spdlog/issues/609 void sleep_for_millis(int milliseconds) SPDLOG_NOEXCEPT; -std::string filename_to_str(const filename_t &filename) SPDLOG_NOEXCEPT; +std::string filename_to_str(const filename_t &filename); int pid() SPDLOG_NOEXCEPT; @@ -80,8 +80,8 @@ bool is_color_terminal() SPDLOG_NOEXCEPT; // Source: https://github.com/agauniyal/rang/ bool in_terminal(FILE *file) SPDLOG_NOEXCEPT; -#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) && defined(_WIN32) -void wbuf_to_utf8buf(const fmt::wmemory_buffer &wbuf, fmt::memory_buffer &target); +#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32) +void wstr_to_utf8buf(basic_string_view_t wstr, fmt::memory_buffer &target); #endif } // namespace os diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index bc627c4b..1d831362 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -243,8 +243,10 @@ public: // format to wmemory_buffer and convert to utf8 fmt::wmemory_buffer wbuf; fmt::format_to(wbuf, fmt, args...); + fmt::memory_buffer buf; - details::os::wbuf_to_utf8buf(wbuf, buf); + details::os::wstr_to_utf8buf(basic_string_view_t(wbuf.data(), wbuf.size()), buf); + details::log_msg log_msg(source, name_, lvl, string_view_t(buf.data(), buf.size())); sink_it_(log_msg); } diff --git a/include/spdlog/sinks/ansicolor_sink-inl.h b/include/spdlog/sinks/ansicolor_sink-inl.h index 74b9c3ec..13a0691e 100644 --- a/include/spdlog/sinks/ansicolor_sink-inl.h +++ b/include/spdlog/sinks/ansicolor_sink-inl.h @@ -7,6 +7,7 @@ #include "spdlog/sinks/ansicolor_sink.h" #endif +#include "spdlog/details/pattern_formatter.h" #include "spdlog/details/os.h" namespace spdlog { @@ -132,4 +133,4 @@ SPDLOG_INLINE ansicolor_stderr_sink::ansicolor_stderr_sink(color_m {} } // namespace sinks -} // namespace spdlog \ No newline at end of file +} // namespace spdlog diff --git a/include/spdlog/sinks/daily_file_sink.h b/include/spdlog/sinks/daily_file_sink.h index 687da043..a0798bee 100644 --- a/include/spdlog/sinks/daily_file_sink.h +++ b/include/spdlog/sinks/daily_file_sink.h @@ -67,10 +67,14 @@ public: protected: void sink_it_(const details::log_msg &msg) override { - - if (msg.time >= rotation_tp_) +#ifdef SPDLOG_NO_DATETIME + auto time = log_clock::now(); +#else + auto time = msg.time; +#endif + if (time >= rotation_tp_) { - file_helper_.open(FileNameCalc::calc_filename(base_filename_, now_tm(msg.time)), truncate_); + file_helper_.open(FileNameCalc::calc_filename(base_filename_, now_tm(time)), truncate_); rotation_tp_ = next_rotation_tp_(); } fmt::memory_buffer formatted; diff --git a/meson.build b/meson.build new file mode 100644 index 00000000..b7d7d452 --- /dev/null +++ b/meson.build @@ -0,0 +1,110 @@ +project('spdlog', ['cpp'], + license : 'MIT', + version : run_command(find_program('scripts/extract_version.py')).stdout().strip(), + default_options : [ + 'warning_level=3', + 'cpp_std=c++11', + 'default_library=static', + 'buildtype=release', + 'b_colorout=always', + ], +) + +# ------------------------ +# --- Dependencies --- +# ------------------------ +dep_list = [] +compile_args = [] + +# Threads +dep_list += dependency('threads') + +# Check for FMT +if get_option('extrenal_fmt') + if not meson.version().version_compare('>=0.49.0') + warning('Finding fmt can fail wit meson versions before 0.49.0') + endif + dep_list += dependency('fmt') + compile_args += '-DSPDLOG_FMT_EXTERNAL' +endif + +# ------------------------------------ +# --- Compiled library version --- +# ------------------------------------ + +spdlog_inc = include_directories('./include') + +spdlog = library('spdlog', ['src/spdlog.cpp'], + cpp_args : [compile_args] + ['-DSPDLOG_COMPILED_LIB'], + include_directories : spdlog_inc, + dependencies : dep_list, + install : true, +) + +spdlog_dep = declare_dependency( + link_with : spdlog, + include_directories : spdlog_inc, + compile_args : compile_args + ['-DSPDLOG_COMPILED_LIB'], + dependencies : dep_list, + version : meson.project_version(), +) + +# ---------------------------------- +# --- Header only dependency --- +# ---------------------------------- + +spdlog_headeronly_dep = declare_dependency( + include_directories : spdlog_inc, + compile_args : compile_args, + dependencies : dep_list, + version : meson.project_version(), +) + +# ------------------------ +# --- Installation --- +# ------------------------ + +install_subdir('include/spdlog', install_dir: get_option('includedir')) + +pkg = import('pkgconfig') +pkg.generate(spdlog, + name : 'spdlog', + description : 'Fast C++ logging library', + url : 'https://github.com/gabime/spdlog', + extra_cflags : ['-DSPDLOG_COMPILED_LIB'] +) + +# ------------------------------------- +# --- Conditionally add subdirs --- +# ------------------------------------- + +if get_option('enable_tests') + subdir('tests') +endif + +if get_option('enable_examples') + subdir('example') +endif + +if get_option('enable_benchmarks') + subdir('bench') +endif + +# ------------------- +# --- Summary --- +# ------------------- + +summary_str = '''spdlog build summary: + + - using extrenal fmt: @0@ + - building tests: @1@ + - building examples: @2@ + - building benchmarks: @3@ +'''.format( + get_option('extrenal_fmt'), + get_option('enable_tests'), + get_option('enable_examples'), + get_option('enable_benchmarks') +) + +message(summary_str) diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 00000000..7dafbf51 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,4 @@ +option('extrenal_fmt', type: 'boolean', value: false) +option('enable_examples', type: 'boolean', value: false) +option('enable_benchmarks', type: 'boolean', value: false) +option('enable_tests', type: 'boolean', value: false) diff --git a/clang_tidy.sh b/scripts/clang_tidy.sh similarity index 53% rename from clang_tidy.sh rename to scripts/clang_tidy.sh index 9ced07f1..8b1b5f88 100755 --- a/clang_tidy.sh +++ b/scripts/clang_tidy.sh @@ -1 +1,6 @@ +#!/bin/bash + +cd "$(dirname "$0")" +cd .. + clang-tidy example/example.cpp -- -I ./include diff --git a/scripts/extract_version.py b/scripts/extract_version.py new file mode 100755 index 00000000..960df51b --- /dev/null +++ b/scripts/extract_version.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 + +import os +import re + +base_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) +config_h = os.path.join(base_path, 'include', 'spdlog', 'version.h') +data = {'MAJOR': 0, 'MINOR': 0, 'PATCH': 0} +reg = re.compile(r'^\s*#define\s+SPDLOG_VER_([A-Z]+)\s+([0-9]+).*$') + +with open(config_h, 'r') as fp: + for l in fp: + m = reg.match(l) + if m: + data[m.group(1)] = int(m.group(2)) + +print('{}.{}.{}'.format(data['MAJOR'], data['MINOR'], data['PATCH'])) diff --git a/format.sh b/scripts/format.sh similarity index 87% rename from format.sh rename to scripts/format.sh index 97bbea23..bffbb4c1 100755 --- a/format.sh +++ b/scripts/format.sh @@ -1,3 +1,8 @@ +#!/bin/bash + +cd "$(dirname "$0")" +cd .. + echo -n "Running dos2unix " find . -name "*\.h" -o -name "*\.cpp"|grep -v bundled|xargs -I {} sh -c "dos2unix '{}' 2>/dev/null; echo -n '.'" echo diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ebd31807..e6d258d8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,7 @@ project(spdlog_utests CXX) +include(../cmake/utils.cmake) + find_package(PkgConfig) if(PkgConfig_FOUND) pkg_check_modules(systemd libsystemd) diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 00000000..9cb7eef4 --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,43 @@ +test_sources = files([ + 'main.cpp', + 'test_async.cpp', + 'test_dup_filter.cpp', + 'test_errors.cpp', + 'test_file_helper.cpp', + 'test_file_logging.cpp', + 'test_fmt_helper.cpp', + 'test_macros.cpp', + 'test_misc.cpp', + 'test_mpmc_q.cpp', + 'test_pattern_formatter.cpp', + 'test_registry.cpp', + 'test_stdout_api.cpp', + 'utils.cpp', +]) + +global_test_deps = [] + +# ----------------------------------------------------- +# --- Add the systemd test if libsystemd is found --- +# ----------------------------------------------------- + +systemd_dep = dependency('libsystemd', required: false) + +if systemd_dep.found() + test_sources += files(['test_systemd.cpp']) + global_test_deps += systemd_dep +endif + +# -------------------------------------- +# --- Build the test executables --- +# -------------------------------------- + +test_matrix = [ + ['spdlog-utest', spdlog_dep], + ['spdlog-utest-ho', spdlog_headeronly_dep], +] + +foreach i : test_matrix + test_exe = executable(i[0], test_sources, dependencies: global_test_deps + [i[1]]) + test('test_' + i[0], test_exe) +endforeach