Compare commits

...

11 Commits

Author SHA1 Message Date
gabime
453be2e08a clang-format 2019-09-23 12:38:19 +03:00
gabime
83497e4dc9 Update test_stdout_api.cpp 2019-09-23 12:11:12 +03:00
gabime
3806a9c320 Added wchar api tests to windows 2019-09-23 12:06:21 +03:00
Gabi Melman
4da95066a0 Merge pull request #1241 from orbea/fmt
cmake: Only install fmt headers when SPDLOG_FMT_EXTERNAL is not defined.
2019-09-23 10:25:48 +03:00
Gabi Melman
ab1105524f Merge pull request #1238 from orbea/pkgconfig
cmake: Add a new spdlog.pc pkgconfig file.
2019-09-23 10:22:36 +03:00
Gabi Melman
d70b743e03 Merge pull request #1240 from Bak-Jin-Hyeong/fix1239
Fix #1239, Remove basic_string_view_t
2019-09-23 10:20:08 +03:00
orbea
920dd078f3 cmake: Only install fmt headers when SPDLOG_FMT_EXTERNAL is not defined. 2019-09-22 23:19:11 -07:00
Bak, Jin Hyeong
f8e780b9dd Fix #1239, Remove basic_string_view_t 2019-09-23 14:48:09 +09:00
orbea
588910129c cmake: Add a new spdlog.pc pkgconfig file.
Fixes https://github.com/gabime/spdlog/issues/1237.
2019-09-22 19:04:29 -07:00
gabime
e42867f0a8 Merge branch 'v1.x' of https://github.com/gabime/spdlog into v1.x 2019-09-21 18:35:33 +03:00
gabime
fe20afac17 clang-format 2019-09-21 18:16:38 +03:00
15 changed files with 111 additions and 72 deletions

View File

@@ -86,6 +86,7 @@ set(SPDLOG_SRCS
src/file_sinks.cpp
src/async.cpp)
set(SPDLOG_CFLAGS "${PROJECT_NAME}")
if (SPDLOG_BUILD_SHARED)
if(WIN32)
@@ -128,6 +129,8 @@ if(SPDLOG_FMT_EXTERNAL)
find_package(fmt REQUIRED)
endif ()
set(SPDLOG_CFLAGS "${SPDLOG_CFLAGS} -DSPDLOG_FMT_EXTERNAL")
target_compile_definitions(spdlog PUBLIC SPDLOG_FMT_EXTERNAL)
target_link_libraries(spdlog PUBLIC fmt::fmt)
@@ -180,16 +183,26 @@ if (SPDLOG_INSTALL)
set(config_targets_file "spdlogConfigTargets.cmake")
set(version_config_file "${CMAKE_CURRENT_BINARY_DIR}/spdlogConfigVersion.cmake")
set(export_dest_dir "${CMAKE_INSTALL_LIBDIR}/spdlog/cmake")
set(pkgconfig_install_dir "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
set(pkg_config "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc")
#---------------------------------------------------------------------------------------
# Include files
#---------------------------------------------------------------------------------------
install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" PATTERN "fmt/bundled" EXCLUDE)
install(TARGETS spdlog spdlog_header_only EXPORT spdlog DESTINATION "${CMAKE_INSTALL_LIBDIR}/spdlog")
if(NOT SPDLOG_FMT_EXTERNAL)
install(DIRECTORY include/${PROJECT_NAME}/fmt/bundled/
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/fmt/bundled/")
endif()
#---------------------------------------------------------------------------------------
# Package and version files
#---------------------------------------------------------------------------------------
configure_file("cmake/${PROJECT_NAME}.pc.in" "${pkg_config}" @ONLY)
install(FILES "${pkg_config}" DESTINATION "${pkgconfig_install_dir}")
install(EXPORT spdlog
DESTINATION ${export_dest_dir}
NAMESPACE spdlog::

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%
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 .. -G %GENERATOR% -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DSPDLOG_WCHAR_SUPPORT=ON -DSPDLOG_BUILD_EXAMPLE=ON -DSPDLOG_BUILD_EXAMPLE_HO=ON -DSPDLOG_BUILD_TESTS=ON -DSPDLOG_BUILD_TESTS_HO=OFF
cmake --build . --config %BUILD_TYPE%

11
cmake/spdlog.pc.in Normal file
View File

@@ -0,0 +1,11 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
Name: lib@PROJECT_NAME@
Description: Fast C++ logging library.
URL: https://github.com/gabime/@PROJECT_NAME@
Version: @SPDLOG_VERSION@
CFlags: -I${includedir}/@SPDLOG_CFLAGS@
Libs: -L${libdir}/@PROJECT_NAME@ -l@PROJECT_NAME@

View File

@@ -107,7 +107,7 @@ using memory_buf_t = fmt::basic_memory_buffer<char, 250>;
#ifndef _WIN32
#error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows
#else
using wstring_view_t = basic_string_view_t<wchar_t>;
using wstring_view_t = fmt::basic_string_view<wchar_t>;
template<typename T>
struct is_convertible_to_wstring_view : std::is_convertible<T, wstring_view_t>

View File

@@ -62,12 +62,12 @@ public:
// Return reference to the front item.
// If there are no elements in the container, the behavior is undefined.
const T& front() const
const T &front() const
{
return v_[head_];
}
T& front()
T &front()
{
return v_[head_];
}
@@ -87,7 +87,7 @@ public:
bool full() const
{
// head is ahead of the tail by 1
if(max_items_ > 0)
if (max_items_ > 0)
{
return ((tail_ + 1) % max_items_) == head_;
}

View File

@@ -10,51 +10,51 @@
namespace spdlog {
namespace details {
SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg &orig_msg)
: log_msg{orig_msg}
{
buffer.append(logger_name.begin(), logger_name.end());
buffer.append(payload.begin(), payload.end());
update_string_views();
}
SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg_buffer &other)
: log_msg{other}
{
buffer.append(logger_name.begin(), logger_name.end());
buffer.append(payload.begin(), payload.end());
update_string_views();
}
SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg &orig_msg)
: log_msg{orig_msg}
{
buffer.append(logger_name.begin(), logger_name.end());
buffer.append(payload.begin(), payload.end());
update_string_views();
}
SPDLOG_INLINE log_msg_buffer:: log_msg_buffer(log_msg_buffer &&other)
: log_msg{std::move(other)}
, buffer{std::move(other.buffer)}
{
update_string_views();
}
SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg_buffer &other)
: log_msg{other}
{
buffer.append(logger_name.begin(), logger_name.end());
buffer.append(payload.begin(), payload.end());
update_string_views();
}
SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(const log_msg_buffer &other)
{
log_msg::operator=(other);
buffer.clear();
buffer.append(other.buffer.data(), other.buffer.data() + other.buffer.size());
update_string_views();
return *this;
}
SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other)
: log_msg{std::move(other)}
, buffer{std::move(other.buffer)}
{
update_string_views();
}
SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(log_msg_buffer &&other)
{
log_msg::operator=(std::move(other));
buffer = std::move(other.buffer);
update_string_views();
return *this;
}
SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(const log_msg_buffer &other)
{
log_msg::operator=(other);
buffer.clear();
buffer.append(other.buffer.data(), other.buffer.data() + other.buffer.size());
update_string_views();
return *this;
}
SPDLOG_INLINE void log_msg_buffer::update_string_views()
{
logger_name = string_view_t{buffer.data(), logger_name.size()};
payload = string_view_t{buffer.data()+logger_name.size(), payload.size()};
}
SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(log_msg_buffer &&other)
{
log_msg::operator=(std::move(other));
buffer = std::move(other.buffer);
update_string_views();
return *this;
}
SPDLOG_INLINE void log_msg_buffer::update_string_views()
{
logger_name = string_view_t{buffer.data(), logger_name.size()};
payload = string_view_t{buffer.data() + logger_name.size(), payload.size()};
}
} // namespace details
} // namespace spdlog

View File

@@ -14,15 +14,15 @@ namespace details {
class log_msg_buffer : public log_msg
{
memory_buf_t buffer;
void update_string_views();
void update_string_views();
public:
log_msg_buffer() = default;
explicit log_msg_buffer(const log_msg &orig_msg);
log_msg_buffer(const log_msg_buffer &other);
log_msg_buffer(log_msg_buffer &&other);
log_msg_buffer &operator=(const log_msg_buffer &other);
explicit log_msg_buffer(const log_msg &orig_msg);
log_msg_buffer(const log_msg_buffer &other);
log_msg_buffer(log_msg_buffer &&other);
log_msg_buffer &operator=(const log_msg_buffer &other);
log_msg_buffer &operator=(log_msg_buffer &&other);
};
} // namespace details
@@ -31,4 +31,3 @@ public:
#ifdef SPDLOG_HEADER_ONLY
#include "log_msg_buffer-inl.h"
#endif

View File

@@ -70,7 +70,7 @@ public:
// apparently mingw deadlocks if the mutex is released before cv.notify_one(),
// so release the mutex at the very end each function.
// try to enqueue and block if no room left
// try to enqueue and block if no room left
void enqueue(T &&item)
{
std::unique_lock<std::mutex> lock(queue_mutex_);
@@ -85,7 +85,6 @@ public:
std::unique_lock<std::mutex> lock(queue_mutex_);
q_.push_back(std::move(item));
push_cv_.notify_one();
}
// try to dequeue item. if no item found. wait upto timeout and try again

View File

@@ -51,16 +51,16 @@
#include <sys/syscall.h> //Use gettid() syscall under linux to get thread id
#elif defined(_AIX)
#include <pthread.h> // for pthread_getthreadid_np
#include <pthread.h> // for pthread_getthreadid_np
#elif defined(__DragonFly__) || defined(__FreeBSD__)
#include <pthread_np.h> // for pthread_getthreadid_np
#include <pthread_np.h> // for pthread_getthreadid_np
#elif defined(__NetBSD__)
#include <lwp.h> // for _lwp_self
#include <lwp.h> // for _lwp_self
#elif defined(__sun)
#include <thread.h> // for thr_self
#include <thread.h> // for thr_self
#endif
#endif // unix
@@ -396,8 +396,8 @@ SPDLOG_INLINE bool is_color_terminal() SPDLOG_NOEXCEPT
#ifdef _WIN32
return true;
#else
static constexpr std::array<const char *, 14> Terms = {{
"ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm", "linux", "msys", "putty", "rxvt", "screen", "vt100", "xterm"}};
static constexpr std::array<const char *, 14> Terms = {
{"ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm", "linux", "msys", "putty", "rxvt", "screen", "vt100", "xterm"}};
const char *env_p = std::getenv("TERM");
if (env_p == nullptr)
@@ -424,7 +424,7 @@ SPDLOG_INLINE bool in_terminal(FILE *file) SPDLOG_NOEXCEPT
}
#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
SPDLOG_INLINE void wstr_to_utf8buf(basic_string_view_t<wchar_t> wstr, memory_buf_t &target)
SPDLOG_INLINE void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target)
{
if (wstr.size() > static_cast<size_t>(std::numeric_limits<int>::max()))
{

View File

@@ -86,7 +86,7 @@ bool is_color_terminal() SPDLOG_NOEXCEPT;
bool in_terminal(FILE *file) SPDLOG_NOEXCEPT;
#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
void wstr_to_utf8buf(basic_string_view_t<wchar_t> wstr, memory_buf_t &target);
void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target);
#endif
} // namespace os

View File

@@ -209,8 +209,8 @@ public:
};
// Full month name
static const std::array<const char *, 12> full_months{{
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}};
static const std::array<const char *, 12> full_months{
{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}};
template<typename ScopedPadder>
class B_formatter : public flag_formatter

View File

@@ -13,7 +13,6 @@
#include "spdlog/details/log_msg.h"
#include "spdlog/sinks/sink.h"
namespace spdlog {
namespace sinks {
template<typename Mutex>

View File

@@ -5,6 +5,6 @@
#define SPDLOG_VER_MAJOR 1
#define SPDLOG_VER_MINOR 4
#define SPDLOG_VER_PATCH 0
#define SPDLOG_VER_PATCH 1
#define SPDLOG_VERSION (SPDLOG_VER_MAJOR * 10000 + SPDLOG_VER_MINOR * 100 + SPDLOG_VER_PATCH)

View File

@@ -77,4 +77,22 @@ TEST_CASE("stderr_color_mt", "[stderr]")
l->error("Test stderr_color_mt");
l->critical("Test stderr_color_mt");
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

View File

@@ -77,15 +77,15 @@ std::size_t count_files(const std::string &folder)
{
size_t counter = 0;
WIN32_FIND_DATA ffd;
// Start iterating over the files in the folder directory.
HANDLE hFind = ::FindFirstFileA((folder + "\\*").c_str(), &ffd);
if (hFind != INVALID_HANDLE_VALUE)
{
do // Managed to locate and create an handle to that folder.
{
if (ffd.cFileName[0] != '.')
counter++;
if (ffd.cFileName[0] != '.')
counter++;
} while (::FindNextFile(hFind, &ffd) != 0);
::FindClose(hFind);
}