mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-29 09:59:33 +08:00
Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1549ff12f1 | ||
![]() |
70357ceff2 | ||
![]() |
cfe7cac1c4 | ||
![]() |
fb70eca0a3 | ||
![]() |
cf2bf488a2 | ||
![]() |
5c02fc47b9 | ||
![]() |
4021e5eea9 | ||
![]() |
5cd0b6272d | ||
![]() |
bf49bebe7a | ||
![]() |
1e8299e893 | ||
![]() |
5381061d97 | ||
![]() |
274558c430 | ||
![]() |
188afe20f9 | ||
![]() |
1add9c9a02 | ||
![]() |
e7d4b99350 | ||
![]() |
8627721533 | ||
![]() |
6696416107 | ||
![]() |
453be2e08a | ||
![]() |
83497e4dc9 | ||
![]() |
3806a9c320 | ||
![]() |
4da95066a0 | ||
![]() |
ab1105524f | ||
![]() |
d70b743e03 | ||
![]() |
920dd078f3 | ||
![]() |
f8e780b9dd | ||
![]() |
588910129c | ||
![]() |
e42867f0a8 | ||
![]() |
fe20afac17 |
@@ -66,6 +66,7 @@ option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF)
|
|||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
option(SPDLOG_WCHAR_SUPPORT "Support wchar api" OFF)
|
option(SPDLOG_WCHAR_SUPPORT "Support wchar api" OFF)
|
||||||
|
option(SPDLOG_WCHAR_FILENAMES "Support wchar filenames" OFF)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
option(SPDLOG_NO_EXCEPTIONS "Compile with -fno-exceptions. Call abort() on any spdlog exceptions" OFF)
|
option(SPDLOG_NO_EXCEPTIONS "Compile with -fno-exceptions. Call abort() on any spdlog exceptions" OFF)
|
||||||
@@ -86,7 +87,6 @@ set(SPDLOG_SRCS
|
|||||||
src/file_sinks.cpp
|
src/file_sinks.cpp
|
||||||
src/async.cpp)
|
src/async.cpp)
|
||||||
|
|
||||||
|
|
||||||
if (SPDLOG_BUILD_SHARED)
|
if (SPDLOG_BUILD_SHARED)
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
message(FATAL_ERROR "spdlog shared lib is not yet supported under windows")
|
message(FATAL_ERROR "spdlog shared lib is not yet supported under windows")
|
||||||
@@ -127,12 +127,13 @@ if(SPDLOG_FMT_EXTERNAL)
|
|||||||
if (NOT TARGET fmt::fmt)
|
if (NOT TARGET fmt::fmt)
|
||||||
find_package(fmt REQUIRED)
|
find_package(fmt REQUIRED)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
target_compile_definitions(spdlog PUBLIC SPDLOG_FMT_EXTERNAL)
|
target_compile_definitions(spdlog PUBLIC SPDLOG_FMT_EXTERNAL)
|
||||||
target_link_libraries(spdlog PUBLIC fmt::fmt)
|
target_link_libraries(spdlog PUBLIC fmt::fmt)
|
||||||
|
|
||||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_FMT_EXTERNAL)
|
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_FMT_EXTERNAL)
|
||||||
target_link_libraries(spdlog_header_only INTERFACE fmt::fmt)
|
target_link_libraries(spdlog_header_only INTERFACE fmt::fmt)
|
||||||
|
|
||||||
|
set(PKG_CONFIG_REQUIRES fmt) # add dependecy to pkg-config
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(SPDLOG_WCHAR_SUPPORT)
|
if(SPDLOG_WCHAR_SUPPORT)
|
||||||
@@ -140,6 +141,11 @@ if(SPDLOG_WCHAR_SUPPORT)
|
|||||||
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_WCHAR_TO_UTF8_SUPPORT)
|
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_WCHAR_TO_UTF8_SUPPORT)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(SPDLOG_WCHAR_FILENAMES)
|
||||||
|
target_compile_definitions(spdlog PUBLIC SPDLOG_WCHAR_FILENAMES)
|
||||||
|
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_WCHAR_FILENAMES)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(SPDLOG_NO_EXCEPTIONS)
|
if(SPDLOG_NO_EXCEPTIONS)
|
||||||
target_compile_definitions(spdlog PUBLIC SPDLOG_NO_EXCEPTIONS)
|
target_compile_definitions(spdlog PUBLIC SPDLOG_NO_EXCEPTIONS)
|
||||||
|
|
||||||
@@ -180,15 +186,31 @@ if (SPDLOG_INSTALL)
|
|||||||
set(config_targets_file "spdlogConfigTargets.cmake")
|
set(config_targets_file "spdlogConfigTargets.cmake")
|
||||||
set(version_config_file "${CMAKE_CURRENT_BINARY_DIR}/spdlogConfigVersion.cmake")
|
set(version_config_file "${CMAKE_CURRENT_BINARY_DIR}/spdlogConfigVersion.cmake")
|
||||||
set(export_dest_dir "${CMAKE_INSTALL_LIBDIR}/spdlog/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
|
# 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")
|
install(TARGETS spdlog spdlog_header_only EXPORT spdlog DESTINATION "${CMAKE_INSTALL_LIBDIR}")
|
||||||
|
|
||||||
|
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
|
# Install pkg-config file
|
||||||
|
#---------------------------------------------------------------------------------------
|
||||||
|
get_target_property(PKG_CONFIG_DEFINES spdlog INTERFACE_COMPILE_DEFINITIONS)
|
||||||
|
string(REPLACE ";" " -D" PKG_CONFIG_DEFINES "${PKG_CONFIG_DEFINES}")
|
||||||
|
string(CONCAT PKG_CONFIG_DEFINES "-D" "${PKG_CONFIG_DEFINES}")
|
||||||
|
configure_file("cmake/${PROJECT_NAME}.pc.in" "${pkg_config}" @ONLY)
|
||||||
|
install(FILES "${pkg_config}" DESTINATION "${pkgconfig_install_dir}")
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------------
|
||||||
|
# Install CMake config files
|
||||||
#---------------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------------
|
||||||
install(EXPORT spdlog
|
install(EXPORT spdlog
|
||||||
DESTINATION ${export_dest_dir}
|
DESTINATION ${export_dest_dir}
|
||||||
@@ -197,6 +219,7 @@ if (SPDLOG_INSTALL)
|
|||||||
|
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
configure_file("${project_config_in}" "${project_config_out}" @ONLY)
|
configure_file("${project_config_in}" "${project_config_out}" @ONLY)
|
||||||
|
|
||||||
write_basic_package_version_file("${version_config_file}" COMPATIBILITY SameMajorVersion)
|
write_basic_package_version_file("${version_config_file}" COMPATIBILITY SameMajorVersion)
|
||||||
install(FILES
|
install(FILES
|
||||||
"${project_config_out}"
|
"${project_config_out}"
|
||||||
@@ -208,3 +231,4 @@ if (SPDLOG_INSTALL)
|
|||||||
include(cmake/spdlogCPack.cmake)
|
include(cmake/spdlogCPack.cmake)
|
||||||
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
@@ -8,7 +8,7 @@ Very fast, header-only/compiled, C++ logging library. [ to your build tree and use a C++11 compiler.
|
Copy the source [folder](https://github.com/gabime/spdlog/tree/v1.x/include/spdlog) to your build tree and use a C++11 compiler.
|
||||||
|
|
||||||
#### Static lib version (recommended - much faster compile times, v1.4.0)
|
#### Static lib version (recommended - much faster compile times)
|
||||||
```console
|
```console
|
||||||
$ git clone https://github.com/gabime/spdlog.git
|
$ git clone https://github.com/gabime/spdlog.git
|
||||||
$ cd spdlog && mkdir build && cd build
|
$ cd spdlog && mkdir build && cd build
|
||||||
|
@@ -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=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%
|
cmake --build . --config %BUILD_TYPE%
|
||||||
|
|
||||||
|
13
cmake/spdlog.pc.in
Normal file
13
cmake/spdlog.pc.in
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
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} @PKG_CONFIG_DEFINES@
|
||||||
|
Libs: -L${libdir} -lspdlog -pthread
|
||||||
|
Requires: @PKG_CONFIG_REQUIRES@
|
||||||
|
|
@@ -14,6 +14,7 @@ set(CPACK_INSTALL_CMAKE_PROJECTS
|
|||||||
set(CPACK_PROJECT_URL "https://github.com/gabime/spdlog")
|
set(CPACK_PROJECT_URL "https://github.com/gabime/spdlog")
|
||||||
set(CPACK_PACKAGE_VENDOR "Gabi Melman")
|
set(CPACK_PACKAGE_VENDOR "Gabi Melman")
|
||||||
set(CPACK_PACKAGE_CONTACT "Gabi Melman <gmelman1@gmail.com>")
|
set(CPACK_PACKAGE_CONTACT "Gabi Melman <gmelman1@gmail.com>")
|
||||||
|
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Fast C++ logging library")
|
||||||
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
|
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
|
||||||
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
|
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
|
||||||
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
|
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
|
||||||
@@ -23,4 +24,9 @@ if (PROJECT_VERSION_TWEAK)
|
|||||||
endif ()
|
endif ()
|
||||||
set(CPACK_PACKAGE_RELOCATABLE ON)
|
set(CPACK_PACKAGE_RELOCATABLE ON)
|
||||||
|
|
||||||
|
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
|
||||||
|
set(CPACK_RPM_PACKAGE_GROUP "System Environment/Libraries")
|
||||||
|
set(CPACK_RPM_PACKAGE_URL ${CPACK_PROJECT_URL})
|
||||||
|
set(CPACK_RPM_PACKAGE_DESCRIPTION "Very fast, header-only/compiled, C++ logging library.")
|
||||||
|
|
||||||
include(CPack)
|
include(CPack)
|
||||||
|
@@ -101,14 +101,13 @@ using sink_ptr = std::shared_ptr<sinks::sink>;
|
|||||||
using sinks_init_list = std::initializer_list<sink_ptr>;
|
using sinks_init_list = std::initializer_list<sink_ptr>;
|
||||||
using err_handler = std::function<void(const std::string &err_msg)>;
|
using err_handler = std::function<void(const std::string &err_msg)>;
|
||||||
using string_view_t = fmt::basic_string_view<char>;
|
using string_view_t = fmt::basic_string_view<char>;
|
||||||
|
using wstring_view_t = fmt::basic_string_view<wchar_t>;
|
||||||
using memory_buf_t = fmt::basic_memory_buffer<char, 250>;
|
using memory_buf_t = fmt::basic_memory_buffer<char, 250>;
|
||||||
|
|
||||||
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows
|
#error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows
|
||||||
#else
|
#else
|
||||||
using wstring_view_t = basic_string_view_t<wchar_t>;
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_convertible_to_wstring_view : std::is_convertible<T, wstring_view_t>
|
struct is_convertible_to_wstring_view : std::is_convertible<T, wstring_view_t>
|
||||||
{};
|
{};
|
||||||
|
@@ -62,12 +62,12 @@ public:
|
|||||||
|
|
||||||
// Return reference to the front item.
|
// Return reference to the front item.
|
||||||
// If there are no elements in the container, the behavior is undefined.
|
// If there are no elements in the container, the behavior is undefined.
|
||||||
const T& front() const
|
const T &front() const
|
||||||
{
|
{
|
||||||
return v_[head_];
|
return v_[head_];
|
||||||
}
|
}
|
||||||
|
|
||||||
T& front()
|
T &front()
|
||||||
{
|
{
|
||||||
return v_[head_];
|
return v_[head_];
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@ public:
|
|||||||
bool full() const
|
bool full() const
|
||||||
{
|
{
|
||||||
// head is ahead of the tail by 1
|
// head is ahead of the tail by 1
|
||||||
if(max_items_ > 0)
|
if (max_items_ > 0)
|
||||||
{
|
{
|
||||||
return ((tail_ + 1) % max_items_) == head_;
|
return ((tail_ + 1) % max_items_) == head_;
|
||||||
}
|
}
|
||||||
|
@@ -10,51 +10,51 @@
|
|||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg &orig_msg)
|
SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg &orig_msg)
|
||||||
: log_msg{orig_msg}
|
: log_msg{orig_msg}
|
||||||
{
|
{
|
||||||
buffer.append(logger_name.begin(), logger_name.end());
|
buffer.append(logger_name.begin(), logger_name.end());
|
||||||
buffer.append(payload.begin(), payload.end());
|
buffer.append(payload.begin(), payload.end());
|
||||||
update_string_views();
|
update_string_views();
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg_buffer &other)
|
SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg_buffer &other)
|
||||||
: log_msg{other}
|
: log_msg{other}
|
||||||
{
|
{
|
||||||
buffer.append(logger_name.begin(), logger_name.end());
|
buffer.append(logger_name.begin(), logger_name.end());
|
||||||
buffer.append(payload.begin(), payload.end());
|
buffer.append(payload.begin(), payload.end());
|
||||||
update_string_views();
|
update_string_views();
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDLOG_INLINE log_msg_buffer:: log_msg_buffer(log_msg_buffer &&other)
|
SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other)
|
||||||
: log_msg{std::move(other)}
|
: log_msg{std::move(other)}
|
||||||
, buffer{std::move(other.buffer)}
|
, buffer{std::move(other.buffer)}
|
||||||
{
|
{
|
||||||
update_string_views();
|
update_string_views();
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(const log_msg_buffer &other)
|
SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(const log_msg_buffer &other)
|
||||||
{
|
{
|
||||||
log_msg::operator=(other);
|
log_msg::operator=(other);
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
buffer.append(other.buffer.data(), other.buffer.data() + other.buffer.size());
|
buffer.append(other.buffer.data(), other.buffer.data() + other.buffer.size());
|
||||||
update_string_views();
|
update_string_views();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(log_msg_buffer &&other)
|
SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(log_msg_buffer &&other)
|
||||||
{
|
{
|
||||||
log_msg::operator=(std::move(other));
|
log_msg::operator=(std::move(other));
|
||||||
buffer = std::move(other.buffer);
|
buffer = std::move(other.buffer);
|
||||||
update_string_views();
|
update_string_views();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDLOG_INLINE void log_msg_buffer::update_string_views()
|
SPDLOG_INLINE void log_msg_buffer::update_string_views()
|
||||||
{
|
{
|
||||||
logger_name = string_view_t{buffer.data(), logger_name.size()};
|
logger_name = string_view_t{buffer.data(), logger_name.size()};
|
||||||
payload = string_view_t{buffer.data()+logger_name.size(), payload.size()};
|
payload = string_view_t{buffer.data() + logger_name.size(), payload.size()};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace details
|
} // namespace details
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
||||||
|
@@ -15,6 +15,7 @@ class log_msg_buffer : public log_msg
|
|||||||
{
|
{
|
||||||
memory_buf_t buffer;
|
memory_buf_t buffer;
|
||||||
void update_string_views();
|
void update_string_views();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
log_msg_buffer() = default;
|
log_msg_buffer() = default;
|
||||||
explicit log_msg_buffer(const log_msg &orig_msg);
|
explicit log_msg_buffer(const log_msg &orig_msg);
|
||||||
@@ -22,7 +23,6 @@ public:
|
|||||||
log_msg_buffer(log_msg_buffer &&other);
|
log_msg_buffer(log_msg_buffer &&other);
|
||||||
log_msg_buffer &operator=(const log_msg_buffer &other);
|
log_msg_buffer &operator=(const log_msg_buffer &other);
|
||||||
log_msg_buffer &operator=(log_msg_buffer &&other);
|
log_msg_buffer &operator=(log_msg_buffer &&other);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace details
|
} // namespace details
|
||||||
@@ -31,4 +31,3 @@ public:
|
|||||||
#ifdef SPDLOG_HEADER_ONLY
|
#ifdef SPDLOG_HEADER_ONLY
|
||||||
#include "log_msg_buffer-inl.h"
|
#include "log_msg_buffer-inl.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -85,7 +85,6 @@ public:
|
|||||||
std::unique_lock<std::mutex> lock(queue_mutex_);
|
std::unique_lock<std::mutex> lock(queue_mutex_);
|
||||||
q_.push_back(std::move(item));
|
q_.push_back(std::move(item));
|
||||||
push_cv_.notify_one();
|
push_cv_.notify_one();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to dequeue item. if no item found. wait upto timeout and try again
|
// try to dequeue item. if no item found. wait upto timeout and try again
|
||||||
|
@@ -396,8 +396,8 @@ SPDLOG_INLINE bool is_color_terminal() SPDLOG_NOEXCEPT
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
static constexpr std::array<const char *, 14> Terms = {{
|
static constexpr std::array<const char *, 14> Terms = {
|
||||||
"ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm", "linux", "msys", "putty", "rxvt", "screen", "vt100", "xterm"}};
|
{"ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm", "linux", "msys", "putty", "rxvt", "screen", "vt100", "xterm"}};
|
||||||
|
|
||||||
const char *env_p = std::getenv("TERM");
|
const char *env_p = std::getenv("TERM");
|
||||||
if (env_p == nullptr)
|
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)
|
#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()))
|
if (wstr.size() > static_cast<size_t>(std::numeric_limits<int>::max()))
|
||||||
{
|
{
|
||||||
|
@@ -86,7 +86,7 @@ bool is_color_terminal() SPDLOG_NOEXCEPT;
|
|||||||
bool in_terminal(FILE *file) SPDLOG_NOEXCEPT;
|
bool in_terminal(FILE *file) SPDLOG_NOEXCEPT;
|
||||||
|
|
||||||
#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32)
|
#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
|
#endif
|
||||||
|
|
||||||
} // namespace os
|
} // namespace os
|
||||||
|
@@ -209,8 +209,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Full month name
|
// Full month name
|
||||||
static const std::array<const char *, 12> full_months{{
|
static const std::array<const char *, 12> full_months{
|
||||||
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}};
|
{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}};
|
||||||
|
|
||||||
template<typename ScopedPadder>
|
template<typename ScopedPadder>
|
||||||
class B_formatter : public flag_formatter
|
class B_formatter : public flag_formatter
|
||||||
@@ -878,7 +878,7 @@ public:
|
|||||||
|
|
||||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override
|
||||||
{
|
{
|
||||||
auto delta = std::max(msg.time - last_message_time_, log_clock::duration::zero());
|
auto delta = (std::max)(msg.time - last_message_time_, log_clock::duration::zero());
|
||||||
auto delta_units = std::chrono::duration_cast<DurationUnits>(delta);
|
auto delta_units = std::chrono::duration_cast<DurationUnits>(delta);
|
||||||
last_message_time_ = msg.time;
|
last_message_time_ = msg.time;
|
||||||
ScopedPadder p(6, padinfo_, dest);
|
ScopedPadder p(6, padinfo_, dest);
|
||||||
|
@@ -205,7 +205,7 @@ SPDLOG_INLINE void logger::dump_backtrace_()
|
|||||||
if (tracer_)
|
if (tracer_)
|
||||||
{
|
{
|
||||||
sink_it_(log_msg{name(), level::info, "****************** Backtrace Start ******************"});
|
sink_it_(log_msg{name(), level::info, "****************** Backtrace Start ******************"});
|
||||||
tracer_.foreach_pop([this](const details::log_msg &msg) { this->sink_it_(msg); });
|
tracer_.foreach_pop([this](const log_msg &msg) { this->sink_it_(msg); });
|
||||||
sink_it_(log_msg{name(), level::info, "****************** Backtrace End ********************"});
|
sink_it_(log_msg{name(), level::info, "****************** Backtrace End ********************"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -218,7 +218,6 @@ SPDLOG_INLINE bool logger::should_flush_(const details::log_msg &msg)
|
|||||||
|
|
||||||
SPDLOG_INLINE void logger::err_handler_(const std::string &msg)
|
SPDLOG_INLINE void logger::err_handler_(const std::string &msg)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (custom_err_handler_)
|
if (custom_err_handler_)
|
||||||
{
|
{
|
||||||
custom_err_handler_(msg);
|
custom_err_handler_(msg);
|
||||||
|
@@ -3,8 +3,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// Thread safe logger (except for set_pattern(..), set_formatter(..) and
|
// Thread safe logger (except for set_error_handler())
|
||||||
// set_error_handler())
|
|
||||||
// Has name, log level, vector of std::shared sink pointers and formatter
|
// Has name, log level, vector of std::shared sink pointers and formatter
|
||||||
// Upon each log write the logger:
|
// Upon each log write the logger:
|
||||||
// 1. Checks if its log level is enough to log the message and if yes:
|
// 1. Checks if its log level is enough to log the message and if yes:
|
||||||
|
@@ -13,7 +13,6 @@
|
|||||||
#include "spdlog/details/log_msg.h"
|
#include "spdlog/details/log_msg.h"
|
||||||
#include "spdlog/sinks/sink.h"
|
#include "spdlog/sinks/sink.h"
|
||||||
|
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace sinks {
|
namespace sinks {
|
||||||
template<typename Mutex>
|
template<typename Mutex>
|
||||||
|
@@ -140,6 +140,10 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::print_range_(const memory_buf_t
|
|||||||
template<typename ConsoleMutex>
|
template<typename ConsoleMutex>
|
||||||
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::write_to_file_(const memory_buf_t &formatted)
|
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::write_to_file_(const memory_buf_t &formatted)
|
||||||
{
|
{
|
||||||
|
if (out_handle_ == nullptr) // no console and no file redirect
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto size = static_cast<DWORD>(formatted.size());
|
auto size = static_cast<DWORD>(formatted.size());
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
{
|
{
|
||||||
|
@@ -5,6 +5,6 @@
|
|||||||
|
|
||||||
#define SPDLOG_VER_MAJOR 1
|
#define SPDLOG_VER_MAJOR 1
|
||||||
#define SPDLOG_VER_MINOR 4
|
#define SPDLOG_VER_MINOR 4
|
||||||
#define SPDLOG_VER_PATCH 0
|
#define SPDLOG_VER_PATCH 2
|
||||||
|
|
||||||
#define SPDLOG_VERSION (SPDLOG_VER_MAJOR * 10000 + SPDLOG_VER_MINOR * 100 + SPDLOG_VER_PATCH)
|
#define SPDLOG_VERSION (SPDLOG_VER_MAJOR * 10000 + SPDLOG_VER_MINOR * 100 + SPDLOG_VER_PATCH)
|
||||||
|
@@ -78,3 +78,21 @@ TEST_CASE("stderr_color_mt", "[stderr]")
|
|||||||
l->critical("Test stderr_color_mt");
|
l->critical("Test stderr_color_mt");
|
||||||
spdlog::drop_all();
|
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
|
Reference in New Issue
Block a user