Merge branch 'v1.x' of https://github.com/gabime/spdlog into v1.x

This commit is contained in:
gabime 2019-07-05 10:45:24 +03:00
commit 517ccc4088
23 changed files with 270 additions and 272 deletions

4
.gitignore vendored
View File

@ -34,6 +34,9 @@ build/*
# Codelite # Codelite
.codelite .codelite
# KDevelop
*.kdev4
# .orig files # .orig files
*.orig *.orig
@ -46,6 +49,7 @@ example/*
!example/example.sln !example/example.sln
!example/example.vcxproj !example/example.vcxproj
!example/CMakeLists.txt !example/CMakeLists.txt
!example/meson.build
!example/multisink.cpp !example/multisink.cpp
!example/jni !example/jni

View File

@ -97,9 +97,9 @@ script:
-DSPDLOG_BUILD_EXAMPLE_HO=ON \ -DSPDLOG_BUILD_EXAMPLE_HO=ON \
-DSPDLOG_BUILD_BENCH=OFF \ -DSPDLOG_BUILD_BENCH=OFF \
-DSPDLOG_BUILD_TESTS=ON \ -DSPDLOG_BUILD_TESTS=ON \
-DSPDLOG_BUILD_TESTS_HO=ON \ -DSPDLOG_BUILD_TESTS_HO=OFf \
-DSPDLOG_SANITIZE_ADDRESS=$ASAN \ -DSPDLOG_SANITIZE_ADDRESS=$ASAN
-DSPDLOG_SANITIZE_THREAD=$TSAN
- make VERBOSE=1 -j2 - make VERBOSE=1 -j2
- ctest -j2 --output-on-failure - ctest -j2 --output-on-failure

View File

@ -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) #### 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. * 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 ## Platforms

View File

@ -26,7 +26,7 @@ build_script:
set PATH=C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin;%PATH% 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% cmake --build . --config %BUILD_TYPE%

13
bench/meson.build Normal file
View File

@ -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

View File

@ -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_<GENNAME>_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 <gmelman1@gmail.com>")
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()

View File

@ -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_<GENNAME>_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 <gmelman1@gmail.com>")
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()

View File

@ -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}")

View File

@ -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()

8
example/meson.build Normal file
View File

@ -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

View File

@ -26,11 +26,6 @@
#include <windows.h> #include <windows.h>
#endif //_WIN32 #endif //_WIN32
#if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
#include <codecvt>
#include <locale>
#endif
#ifdef SPDLOG_COMPILED_LIB #ifdef SPDLOG_COMPILED_LIB
#undef SPDLOG_HEADER_ONLY #undef SPDLOG_HEADER_ONLY
#define SPDLOG_INLINE #define SPDLOG_INLINE
@ -80,11 +75,6 @@ class sink;
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) #if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
using filename_t = std::wstring; using filename_t = std::wstring;
#define SPDLOG_FILENAME_T(s) L##s #define SPDLOG_FILENAME_T(s) L##s
inline std::string filename_to_str(const filename_t &filename)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> c;
return c.to_bytes(filename);
}
#else #else
using filename_t = std::string; using filename_t = std::string;
#define SPDLOG_FILENAME_T(s) s #define SPDLOG_FILENAME_T(s) s
@ -97,10 +87,13 @@ using err_handler = std::function<void(const std::string &err_msg)>;
// string_view type - either std::string_view or fmt::string_view (pre c++17) // string_view type - either std::string_view or fmt::string_view (pre c++17)
#if defined(FMT_USE_STD_STRING_VIEW) #if defined(FMT_USE_STD_STRING_VIEW)
using string_view_t = std::string_view; template<typename T>
using basic_string_view_t = std::basic_string_view<T>;
#else #else
using string_view_t = fmt::string_view; template<typename T>
using basic_string_view_t = fmt::basic_string_view<T>;
#endif #endif
using string_view_t = basic_string_view_t<char>;
#if defined(SPDLOG_NO_ATOMIC_LEVELS) #if defined(SPDLOG_NO_ATOMIC_LEVELS)
using level_t = details::null_atomic_int; using level_t = details::null_atomic_int;

View File

@ -36,6 +36,10 @@
#include <share.h> #include <share.h>
#endif #endif
#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)
#include <limits>
#endif
#else // unix #else // unix
#include <fcntl.h> #include <fcntl.h>
@ -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) // wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined)
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) #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<std::codecvt_utf8<wchar_t>, wchar_t> c; fmt::memory_buffer buf;
return c.to_bytes(filename); wstr_to_utf8buf(filename, buf);
return fmt::to_string(buf);
} }
#else #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; return filename;
} }
@ -398,28 +403,42 @@ SPDLOG_INLINE bool in_terminal(FILE *file) SPDLOG_NOEXCEPT
#endif #endif
} }
#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) && defined(_WIN32) #if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
SPDLOG_INLINE void wbuf_to_utf8buf(const fmt::wmemory_buffer &wbuf, fmt::memory_buffer &target) SPDLOG_INLINE void wstr_to_utf8buf(basic_string_view_t<wchar_t> wstr, fmt::memory_buffer &target)
{ {
int wbuf_size = static_cast<int>(wbuf.size()); if (wstr.size() > static_cast<size_t>(std::numeric_limits<int>::max()))
if (wbuf_size == 0)
{ {
throw spdlog::spdlog_ex("UTF-16 string is too big to be converted to UTF-8");
}
int wstr_size = static_cast<int>(wstr.size());
if (wstr_size == 0)
{
target.resize(0);
return; return;
} }
auto result_size = ::WideCharToMultiByte(CP_UTF8, 0, wbuf.data(), wbuf_size, NULL, 0, NULL, NULL); int result_size = static_cast<int>(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) if (result_size > 0)
{ {
target.resize(result_size); target.resize(result_size);
::WideCharToMultiByte(CP_UTF8, 0, wbuf.data(), wbuf_size, &target.data()[0], result_size, NULL, NULL); result_size = ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size, target.data(), result_size, NULL, NULL);
}
else if (result_size > 0)
{ {
throw spdlog::spdlog_ex(fmt::format("WideCharToMultiByte failed. Last error: {}", ::GetLastError())); 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 os
} // namespace details } // namespace details

View File

@ -68,7 +68,7 @@ size_t thread_id() SPDLOG_NOEXCEPT;
// See https://github.com/gabime/spdlog/issues/609 // See https://github.com/gabime/spdlog/issues/609
void sleep_for_millis(int milliseconds) SPDLOG_NOEXCEPT; 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; int pid() SPDLOG_NOEXCEPT;
@ -80,8 +80,8 @@ bool is_color_terminal() SPDLOG_NOEXCEPT;
// Source: https://github.com/agauniyal/rang/ // Source: https://github.com/agauniyal/rang/
bool in_terminal(FILE *file) SPDLOG_NOEXCEPT; bool in_terminal(FILE *file) SPDLOG_NOEXCEPT;
#if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) && defined(_WIN32) #if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
void wbuf_to_utf8buf(const fmt::wmemory_buffer &wbuf, fmt::memory_buffer &target); void wstr_to_utf8buf(basic_string_view_t<wchar_t> wstr, fmt::memory_buffer &target);
#endif #endif
} // namespace os } // namespace os

View File

@ -243,8 +243,10 @@ public:
// format to wmemory_buffer and convert to utf8 // format to wmemory_buffer and convert to utf8
fmt::wmemory_buffer wbuf; fmt::wmemory_buffer wbuf;
fmt::format_to(wbuf, fmt, args...); fmt::format_to(wbuf, fmt, args...);
fmt::memory_buffer buf; fmt::memory_buffer buf;
details::os::wbuf_to_utf8buf(wbuf, buf); details::os::wstr_to_utf8buf(basic_string_view_t<wchar_t>(wbuf.data(), wbuf.size()), buf);
details::log_msg log_msg(source, name_, lvl, string_view_t(buf.data(), buf.size())); details::log_msg log_msg(source, name_, lvl, string_view_t(buf.data(), buf.size()));
sink_it_(log_msg); sink_it_(log_msg);
} }

View File

@ -7,6 +7,7 @@
#include "spdlog/sinks/ansicolor_sink.h" #include "spdlog/sinks/ansicolor_sink.h"
#endif #endif
#include "spdlog/details/pattern_formatter.h"
#include "spdlog/details/os.h" #include "spdlog/details/os.h"
namespace spdlog { namespace spdlog {

View File

@ -67,10 +67,14 @@ public:
protected: protected:
void sink_it_(const details::log_msg &msg) override void sink_it_(const details::log_msg &msg) override
{ {
#ifdef SPDLOG_NO_DATETIME
if (msg.time >= rotation_tp_) 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_(); rotation_tp_ = next_rotation_tp_();
} }
fmt::memory_buffer formatted; fmt::memory_buffer formatted;

110
meson.build Normal file
View File

@ -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)

4
meson_options.txt Normal file
View File

@ -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)

View File

@ -1 +1,6 @@
#!/bin/bash
cd "$(dirname "$0")"
cd ..
clang-tidy example/example.cpp -- -I ./include clang-tidy example/example.cpp -- -I ./include

17
scripts/extract_version.py Executable file
View File

@ -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']))

View File

@ -1,3 +1,8 @@
#!/bin/bash
cd "$(dirname "$0")"
cd ..
echo -n "Running dos2unix " echo -n "Running dos2unix "
find . -name "*\.h" -o -name "*\.cpp"|grep -v bundled|xargs -I {} sh -c "dos2unix '{}' 2>/dev/null; echo -n '.'" find . -name "*\.h" -o -name "*\.cpp"|grep -v bundled|xargs -I {} sh -c "dos2unix '{}' 2>/dev/null; echo -n '.'"
echo echo

View File

@ -1,5 +1,7 @@
project(spdlog_utests CXX) project(spdlog_utests CXX)
include(../cmake/utils.cmake)
find_package(PkgConfig) find_package(PkgConfig)
if(PkgConfig_FOUND) if(PkgConfig_FOUND)
pkg_check_modules(systemd libsystemd) pkg_check_modules(systemd libsystemd)

43
tests/meson.build Normal file
View File

@ -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