1
0
mirror of https://github.com/gabime/spdlog.git synced 2025-04-29 20:13:52 +00:00

clang-format

This commit is contained in:
gabime 2021-07-19 00:50:51 +03:00
parent e98265a49b
commit e7e8b75a4c
75 changed files with 655 additions and 654 deletions

View File

@ -100,14 +100,14 @@ 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) option(SPDLOG_WCHAR_FILENAMES "Support wchar filenames" OFF)
else() else()
SET(SPDLOG_WCHAR_SUPPORT OFF CACHE BOOL "non supported option" FORCE) set(SPDLOG_WCHAR_SUPPORT OFF CACHE BOOL "non supported option" FORCE)
SET(SPDLOG_WCHAR_FILENAMES OFF CACHE BOOL "non supported option" FORCE) set(SPDLOG_WCHAR_FILENAMES OFF CACHE BOOL "non supported option" FORCE)
endif() endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
option(SPDLOG_CLOCK_COARSE "Use CLOCK_REALTIME_COARSE instead of the regular clock," OFF) option(SPDLOG_CLOCK_COARSE "Use CLOCK_REALTIME_COARSE instead of the regular clock," OFF)
else() else()
SET(SPDLOG_CLOCK_COARSE OFF CACHE BOOL "non supported option" FORCE) set(SPDLOG_CLOCK_COARSE OFF CACHE BOOL "non supported option" FORCE)
endif() endif()
option(SPDLOG_PREVENT_CHILD_FD "Prevent from child processes to inherit log file descriptors" OFF) option(SPDLOG_PREVENT_CHILD_FD "Prevent from child processes to inherit log file descriptors" OFF)
@ -149,8 +149,8 @@ if (SPDLOG_BUILD_SHARED OR BUILD_SHARED_LIBS)
add_library(spdlog SHARED ${SPDLOG_SRCS} ${SPDLOG_ALL_HEADERS}) add_library(spdlog SHARED ${SPDLOG_SRCS} ${SPDLOG_ALL_HEADERS})
target_compile_definitions(spdlog PUBLIC SPDLOG_SHARED_LIB) target_compile_definitions(spdlog PUBLIC SPDLOG_SHARED_LIB)
if(MSVC) if(MSVC)
target_compile_options(spdlog PUBLIC target_compile_options(spdlog PUBLIC $<$<AND:$<CXX_COMPILER_ID:MSVC>,$<NOT:$<COMPILE_LANGUAGE:CUDA>>>:/wd4251
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<NOT:$<COMPILE_LANGUAGE:CUDA>>>:/wd4251 /wd4275>) /wd4275>)
endif() endif()
if(NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO) if(NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
target_compile_definitions(spdlog PRIVATE FMT_EXPORT PUBLIC FMT_SHARED) target_compile_definitions(spdlog PRIVATE FMT_EXPORT PUBLIC FMT_SHARED)
@ -240,7 +240,6 @@ if (SPDLOG_NO_EXCEPTIONS AND NOT MSVC)
target_compile_options(spdlog PRIVATE -fno-exceptions) target_compile_options(spdlog PRIVATE -fno-exceptions)
endif() endif()
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
# Build binaries # Build binaries
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
@ -318,4 +317,3 @@ if (SPDLOG_INSTALL)
# --------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------
include(cmake/spdlogCPack.cmake) include(cmake/spdlogCPack.cmake)
endif() endif()

View File

@ -18,9 +18,7 @@ if (NOT benchmark_FOUND)
include(FetchContent) include(FetchContent)
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE INTERNAL "") set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE INTERNAL "")
# Do not build and run googlebenchmark tests # Do not build and run googlebenchmark tests
FetchContent_Declare(googlebenchmark FetchContent_Declare(googlebenchmark GIT_REPOSITORY https://github.com/google/benchmark.git GIT_TAG v1.5.2)
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.5.2)
FetchContent_MakeAvailable(googlebenchmark) FetchContent_MakeAvailable(googlebenchmark)
else() else()

View File

@ -60,4 +60,3 @@ function(spdlog_enable_sanitizer target_name)
target_compile_options(${target_name} PRIVATE -fno-omit-frame-pointer) target_compile_options(${target_name} PRIVATE -fno-omit-frame-pointer)
target_link_libraries(${target_name} PRIVATE -fsanitize=address,undefined -fuse-ld=gold) target_link_libraries(${target_name} PRIVATE -fsanitize=address,undefined -fuse-ld=gold)
endfunction() endfunction()

View File

@ -43,4 +43,3 @@ public:
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
# include "backtracer-inl.h" # include "backtracer-inl.h"
#endif #endif

View File

@ -26,9 +26,7 @@ SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg_buffer &other)
update_string_views(); update_string_views();
} }
SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT : log_msg{other}, buffer{std::move(other.buffer)}
: log_msg{other}
, buffer{std::move(other.buffer)}
{ {
update_string_views(); update_string_views();
} }

View File

@ -22,4 +22,3 @@ struct synchronous_factory
} }
}; };
} // namespace spdlog } // namespace spdlog

View File

@ -25,4 +25,3 @@
# include <fmt/core.h> # include <fmt/core.h>
# include <fmt/format.h> # include <fmt/format.h>
#endif #endif

View File

@ -56,4 +56,3 @@ inline std::shared_ptr<logger> basic_logger_st(const std::string &logger_name, c
#ifdef SPDLOG_HEADER_ONLY #ifdef SPDLOG_HEADER_ONLY
# include "basic_file_sink-inl.h" # include "basic_file_sink-inl.h"
#endif #endif

View File

@ -31,8 +31,8 @@ struct hourly_filename_calculator
{ {
filename_t basename, ext; filename_t basename, ext;
std::tie(basename, ext) = details::file_helper::split_by_extension(filename); std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
return fmt::format( return fmt::format(SPDLOG_FILENAME_T("{}_{:04d}{:02d}{:02d}_{:02d}{}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1,
SPDLOG_FILENAME_T("{}_{:04d}{:02d}{:02d}_{:02d}{}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday, now_tm.tm_hour, ext); now_tm.tm_mday, now_tm.tm_hour, ext);
} }
}; };

View File

@ -25,34 +25,41 @@
namespace spdlog { namespace spdlog {
namespace sinks { namespace sinks {
template <typename Mutex> class mongo_sink : public base_sink<Mutex> { template<typename Mutex>
class mongo_sink : public base_sink<Mutex>
{
public: public:
mongo_sink(const std::string &db_name, const std::string &collection_name, mongo_sink(const std::string &db_name, const std::string &collection_name, const std::string &uri = "mongodb://localhost:27017")
const std::string &uri = "mongodb://localhost:27017") { {
try { try
{
client_ = std::make_unique<mongocxx::client>(mongocxx::uri{uri}); client_ = std::make_unique<mongocxx::client>(mongocxx::uri{uri});
db_name_ = db_name; db_name_ = db_name;
coll_name_ = collection_name; coll_name_ = collection_name;
} catch (const std::exception) { }
catch (const std::exception)
{
throw spdlog_ex("Error opening database"); throw spdlog_ex("Error opening database");
} }
} }
~mongo_sink() { flush_(); } ~mongo_sink()
{
flush_();
}
protected: protected:
void sink_it_(const details::log_msg &msg) override { void sink_it_(const details::log_msg &msg) override
{
using bsoncxx::builder::stream::document; using bsoncxx::builder::stream::document;
using bsoncxx::builder::stream::finalize; using bsoncxx::builder::stream::finalize;
if (client_ != nullptr) { if (client_ != nullptr)
auto doc = document{} {
<< "timestamp" << bsoncxx::types::b_date(msg.time) << "level" auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level" << level::to_string_view(msg.level).data()
<< level::to_string_view(msg.level).data() << "message" << "message" << std::string(msg.payload.begin(), msg.payload.end()) << "logger_name"
<< std::string(msg.payload.begin(), msg.payload.end()) << std::string(msg.logger_name.begin(), msg.logger_name.end()) << "thread_id"
<< "logger_name" << static_cast<int>(msg.thread_id) << finalize;
<< std::string(msg.logger_name.begin(), msg.logger_name.end())
<< "thread_id" << static_cast<int>(msg.thread_id) << finalize;
client_->database(db_name_).collection(coll_name_).insert_one(doc.view()); client_->database(db_name_).collection(coll_name_).insert_one(doc.view());
} }
} }
@ -75,22 +82,17 @@ using mongo_sink_st = mongo_sink<spdlog::details::null_mutex>;
} // namespace sinks } // namespace sinks
template<typename Factory = spdlog::synchronous_factory> template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> inline std::shared_ptr<logger> mongo_logger_mt(const std::string &logger_name, const std::string &db_name,
mongo_logger_mt(const std::string &logger_name, const std::string &db_name, const std::string &collection_name, const std::string &uri = "mongodb://localhost:27017")
const std::string &collection_name, {
const std::string &uri = "mongodb://localhost:27017") { return Factory::template create<sinks::mongo_sink_mt>(logger_name, db_name, collection_name, uri);
return Factory::template create<sinks::mongo_sink_mt>(logger_name, db_name,
collection_name, uri);
} }
template<typename Factory = spdlog::synchronous_factory> template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> inline std::shared_ptr<logger> mongo_logger_st(const std::string &logger_name, const std::string &db_name,
mongo_logger_st(const std::string &logger_name, const std::string &db_name, const std::string &collection_name, const std::string &uri = "mongodb://localhost:27017")
const std::string &collection_name, {
const std::string &uri = "mongodb://localhost:27017") { return Factory::template create<sinks::mongo_sink_st>(logger_name, db_name, collection_name, uri);
return Factory::template create<sinks::mongo_sink_st>(logger_name, db_name,
collection_name, uri);
} }
} // namespace spdlog } // namespace spdlog

View File

@ -11,7 +11,6 @@
# include <mutex> # include <mutex>
# include <string> # include <string>
// Avoid including windows.h (https://stackoverflow.com/a/30741042) // Avoid including windows.h (https://stackoverflow.com/a/30741042)
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString); extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString);

View File

@ -22,22 +22,24 @@ namespace _sinks_p {
// //
// Private class for QTextEdit and its derivatives // Private class for QTextEdit and its derivatives
// //
class qtextedit_sink_p : public QObject { class qtextedit_sink_p : public QObject
{
Q_OBJECT Q_OBJECT
public: public:
qtextedit_sink_p(QTextEdit *textedit = nullptr) { qtextedit_sink_p(QTextEdit *textedit = nullptr)
if (textedit != nullptr) { {
if (textedit != nullptr)
{
textedit_ = textedit; textedit_ = textedit;
connect(this, &qtextedit_sink_p::append_text, textedit_, connect(this, &qtextedit_sink_p::append_text, textedit_, &QTextEdit::append);
&QTextEdit::append);
} }
} }
~qtextedit_sink_p() {} ~qtextedit_sink_p() {}
void append(const spdlog::string_view_t &str) { void append(const spdlog::string_view_t &str)
emit append_text( {
QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2))); emit append_text(QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
} }
signals: signals:
@ -50,22 +52,24 @@ private:
// //
// Private class for QPlainTextEdit // Private class for QPlainTextEdit
// //
class qplaintextedit_sink_p : public QObject { class qplaintextedit_sink_p : public QObject
{
Q_OBJECT Q_OBJECT
public: public:
qplaintextedit_sink_p(QPlainTextEdit *textedit = nullptr) { qplaintextedit_sink_p(QPlainTextEdit *textedit = nullptr)
if (textedit != nullptr) { {
if (textedit != nullptr)
{
textedit_ = textedit; textedit_ = textedit;
connect(this, &qplaintextedit_sink_p::append_text, textedit_, connect(this, &qplaintextedit_sink_p::append_text, textedit_, &QPlainTextEdit::appendPlainText);
&QPlainTextEdit::appendPlainText);
} }
} }
~qplaintextedit_sink_p() {} ~qplaintextedit_sink_p() {}
void append(const spdlog::string_view_t &str) { void append(const spdlog::string_view_t &str)
emit append_text( {
QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2))); emit append_text(QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
} }
signals: signals:
@ -82,21 +86,30 @@ private:
// //
namespace spdlog { namespace spdlog {
namespace sinks { namespace sinks {
template <typename Mutex> class qtextedit_sink : public base_sink<Mutex> { template<typename Mutex>
class qtextedit_sink : public base_sink<Mutex>
{
public: public:
qtextedit_sink(QTextEdit *textedit = nullptr) { qtextedit_sink(QTextEdit *textedit = nullptr)
if (textedit != nullptr) { {
textedit_p = if (textedit != nullptr)
std::make_shared<_spdlog_p::_sinks_p::qtextedit_sink_p>(textedit); {
} else { textedit_p = std::make_shared<_spdlog_p::_sinks_p::qtextedit_sink_p>(textedit);
}
else
{
throw spdlog_ex("Error opening QTextEdit"); throw spdlog_ex("Error opening QTextEdit");
} }
} }
~qtextedit_sink() { flush_(); } ~qtextedit_sink()
{
flush_();
}
protected: protected:
void sink_it_(const details::log_msg &msg) override { void sink_it_(const details::log_msg &msg) override
{
memory_buf_t formatted; memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted); base_sink<Mutex>::formatter_->format(msg, formatted);
string_view_t str_v = string_view_t(formatted.data(), formatted.size()); string_view_t str_v = string_view_t(formatted.data(), formatted.size());
@ -112,21 +125,30 @@ private:
// //
// qplaintextedit_sink class // qplaintextedit_sink class
// //
template <typename Mutex> class qplaintextedit_sink : public base_sink<Mutex> { template<typename Mutex>
class qplaintextedit_sink : public base_sink<Mutex>
{
public: public:
qplaintextedit_sink(QPlainTextEdit *textedit = nullptr) { qplaintextedit_sink(QPlainTextEdit *textedit = nullptr)
if (textedit != nullptr) { {
textedit_p = std::make_shared<_spdlog_p::_sinks_p::qplaintextedit_sink_p>( if (textedit != nullptr)
textedit); {
} else { textedit_p = std::make_shared<_spdlog_p::_sinks_p::qplaintextedit_sink_p>(textedit);
}
else
{
throw spdlog_ex("Error opening QPlainTextEdit"); throw spdlog_ex("Error opening QPlainTextEdit");
} }
} }
~qplaintextedit_sink() { flush_(); } ~qplaintextedit_sink()
{
flush_();
}
protected: protected:
void sink_it_(const details::log_msg &msg) override { void sink_it_(const details::log_msg &msg) override
{
memory_buf_t formatted; memory_buf_t formatted;
base_sink<Mutex>::formatter_->format(msg, formatted); base_sink<Mutex>::formatter_->format(msg, formatted);
string_view_t str_v = string_view_t(formatted.data(), formatted.size()); string_view_t str_v = string_view_t(formatted.data(), formatted.size());
@ -136,8 +158,7 @@ protected:
void flush_() override {} void flush_() override {}
private: private:
std::shared_ptr<_spdlog_p::_sinks_p::qplaintextedit_sink_p> textedit_p = std::shared_ptr<_spdlog_p::_sinks_p::qplaintextedit_sink_p> textedit_p = nullptr;
nullptr;
}; };
#include "spdlog/details/null_mutex.h" #include "spdlog/details/null_mutex.h"
@ -154,34 +175,26 @@ using qplaintextedit_sink_st = qplaintextedit_sink<spdlog::details::null_mutex>;
// Factory functions // Factory functions
// //
template<typename Factory = spdlog::synchronous_factory> template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> inline std::shared_ptr<logger> qtextedit_logger_mt(const std::string &logger_name, QTextEdit *qtextedit = nullptr)
qtextedit_logger_mt(const std::string &logger_name, {
QTextEdit *qtextedit = nullptr) { return Factory::template create<sinks::qtextedit_sink_mt>(logger_name, qtextedit);
return Factory::template create<sinks::qtextedit_sink_mt>(logger_name,
qtextedit);
} }
template<typename Factory = spdlog::synchronous_factory> template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> inline std::shared_ptr<logger> qtextedit_logger_st(const std::string &logger_name, QTextEdit *qtextedit = nullptr)
qtextedit_logger_st(const std::string &logger_name, {
QTextEdit *qtextedit = nullptr) { return Factory::template create<sinks::qtextedit_sink_st>(logger_name, qtextedit);
return Factory::template create<sinks::qtextedit_sink_st>(logger_name,
qtextedit);
} }
template<typename Factory = spdlog::synchronous_factory> template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> inline std::shared_ptr<logger> qplaintextedit_logger_mt(const std::string &logger_name, QPlainTextEdit *qplaintextedit = nullptr)
qplaintextedit_logger_mt(const std::string &logger_name, {
QPlainTextEdit *qplaintextedit = nullptr) { return Factory::template create<sinks::qplaintextedit_sink_mt>(logger_name, qplaintextedit);
return Factory::template create<sinks::qplaintextedit_sink_mt>(
logger_name, qplaintextedit);
} }
template<typename Factory = spdlog::synchronous_factory> template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> inline std::shared_ptr<logger> qplaintextedit_logger_st(const std::string &logger_name, QPlainTextEdit *qplaintextedit = nullptr)
qplaintextedit_logger_st(const std::string &logger_name, {
QPlainTextEdit *qplaintextedit = nullptr) { return Factory::template create<sinks::qplaintextedit_sink_st>(logger_name, qplaintextedit);
return Factory::template create<sinks::qplaintextedit_sink_st>(
logger_name, qplaintextedit);
} }
} // namespace spdlog } // namespace spdlog

View File

@ -36,4 +36,3 @@ SPDLOG_INLINE std::shared_ptr<logger> stderr_color_st(const std::string &logger_
return Factory::template create<sinks::stderr_color_sink_st>(logger_name, mode); return Factory::template create<sinks::stderr_color_sink_st>(logger_name, mode);
} }
} // namespace spdlog } // namespace spdlog

View File

@ -11,4 +11,3 @@
#include <spdlog/details/thread_pool-inl.h> #include <spdlog/details/thread_pool-inl.h>
template class SPDLOG_API spdlog::details::mpmc_blocking_queue<spdlog::details::async_msg>; template class SPDLOG_API spdlog::details::mpmc_blocking_queue<spdlog::details::async_msg>;

View File

@ -6,4 +6,3 @@
#endif #endif
#include <spdlog/cfg/helpers-inl.h> #include <spdlog/cfg/helpers-inl.h>

View File

@ -49,4 +49,3 @@ template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_color_mt<spdl
const std::string &logger_name, color_mode mode); const std::string &logger_name, color_mode mode);
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_color_st<spdlog::async_factory>( template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_color_st<spdlog::async_factory>(
const std::string &logger_name, color_mode mode); const std::string &logger_name, color_mode mode);

View File

@ -18,4 +18,3 @@ template class SPDLOG_API spdlog::sinks::basic_file_sink<spdlog::details::null_m
#include <spdlog/sinks/rotating_file_sink-inl.h> #include <spdlog/sinks/rotating_file_sink-inl.h>
template class SPDLOG_API spdlog::sinks::rotating_file_sink<std::mutex>; template class SPDLOG_API spdlog::sinks::rotating_file_sink<std::mutex>;
template class SPDLOG_API spdlog::sinks::rotating_file_sink<spdlog::details::null_mutex>; template class SPDLOG_API spdlog::sinks::rotating_file_sink<spdlog::details::null_mutex>;

View File

@ -24,4 +24,3 @@
template SPDLOG_API spdlog::logger::logger(std::string name, sinks_init_list::iterator begin, sinks_init_list::iterator end); template SPDLOG_API spdlog::logger::logger(std::string name, sinks_init_list::iterator begin, sinks_init_list::iterator end);
template class SPDLOG_API spdlog::sinks::base_sink<std::mutex>; template class SPDLOG_API spdlog::sinks::base_sink<std::mutex>;
template class SPDLOG_API spdlog::sinks::base_sink<spdlog::details::null_mutex>; template class SPDLOG_API spdlog::sinks::base_sink<spdlog::details::null_mutex>;

View File

@ -27,4 +27,3 @@ template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_logger_mt<spd
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_logger_st<spdlog::async_factory>(const std::string &logger_name); template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_logger_st<spdlog::async_factory>(const std::string &logger_name);
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_logger_mt<spdlog::async_factory>(const std::string &logger_name); template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_logger_mt<spdlog::async_factory>(const std::string &logger_name);
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_logger_st<spdlog::async_factory>(const std::string &logger_name); template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_logger_st<spdlog::async_factory>(const std::string &logger_name);

View File

@ -27,7 +27,8 @@ TEST_CASE("create_dir", "[create_dir]")
// test backslash folder separator // test backslash folder separator
REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\dir1\\dir222"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir222"))); REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\dir1\\dir222"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir222")));
REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\dir1\\dir223\\"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir223\\"))); REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\dir1\\dir223\\"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir223\\")));
REQUIRE(try_create_dir(SPDLOG_FILENAME_T(".\\test_logs\\dir1\\dir2\\dir99\\..\\dir23"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir2\\dir23"))); REQUIRE(
try_create_dir(SPDLOG_FILENAME_T(".\\test_logs\\dir1\\dir2\\dir99\\..\\dir23"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir2\\dir23")));
REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\..\\test_logs\\dir1\\dir5"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir5"))); REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\..\\test_logs\\dir1\\dir5"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir5")));
#endif #endif
} }

View File

@ -15,7 +15,8 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger]")
spdlog::filename_t basename = SPDLOG_FILENAME_T("test_logs/daily_dateonly"); spdlog::filename_t basename = SPDLOG_FILENAME_T("test_logs/daily_dateonly");
std::tm tm = spdlog::details::os::localtime(); std::tm tm = spdlog::details::os::localtime();
filename_memory_buf_t w; filename_memory_buf_t w;
fmt::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}"), basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); fmt::format_to(
std::back_inserter(w), SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}"), basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
auto logger = spdlog::create<sink_type>("logger", basename, 0, 0); auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
@ -40,8 +41,8 @@ struct custom_daily_file_name_calculator
static spdlog::filename_t calc_filename(const spdlog::filename_t &basename, const tm &now_tm) static spdlog::filename_t calc_filename(const spdlog::filename_t &basename, const tm &now_tm)
{ {
filename_memory_buf_t w; filename_memory_buf_t w;
fmt::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename, now_tm.tm_year + 1900, fmt::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1,
now_tm.tm_mon + 1, now_tm.tm_mday); now_tm.tm_mday);
return fmt::to_string(w); return fmt::to_string(w);
} }
}; };
@ -56,7 +57,8 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger]")
spdlog::filename_t basename = SPDLOG_FILENAME_T("test_logs/daily_dateonly"); spdlog::filename_t basename = SPDLOG_FILENAME_T("test_logs/daily_dateonly");
std::tm tm = spdlog::details::os::localtime(); std::tm tm = spdlog::details::os::localtime();
filename_memory_buf_t w; filename_memory_buf_t w;
fmt::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); fmt::format_to(
std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
auto logger = spdlog::create<sink_type>("logger", basename, 0, 0); auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
@ -106,9 +108,11 @@ TEST_CASE("rotating_file_sink::calc_filename3", "[rotating_file_sink]]")
TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]]") TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]]")
{ {
// daily_YYYY-MM-DD_hh-mm.txt // daily_YYYY-MM-DD_hh-mm.txt
auto filename = spdlog::sinks::daily_filename_calculator::calc_filename(SPDLOG_FILENAME_T("daily.txt"), spdlog::details::os::localtime()); auto filename =
spdlog::sinks::daily_filename_calculator::calc_filename(SPDLOG_FILENAME_T("daily.txt"), spdlog::details::os::localtime());
// date regex based on https://www.regular-expressions.info/dates.html // date regex based on https://www.regular-expressions.info/dates.html
std::basic_regex<spdlog::filename_t::value_type> re(SPDLOG_FILENAME_T(R"(^daily_(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])\.txt$)")); std::basic_regex<spdlog::filename_t::value_type> re(
SPDLOG_FILENAME_T(R"(^daily_(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])\.txt$)"));
std::match_results<spdlog::filename_t::const_iterator> match; std::match_results<spdlog::filename_t::const_iterator> match;
REQUIRE(std::regex_match(filename, match, re)); REQUIRE(std::regex_match(filename, match, re));
} }

View File

@ -87,5 +87,4 @@ TEST_CASE("dup_filter_test5", "[dup_filter_sink]")
REQUIRE(test_sink->msg_counter() == 3); // skip 2 messages but log the "skipped.." message before message2 REQUIRE(test_sink->msg_counter() == 3); // skip 2 messages but log the "skipped.." message before message2
REQUIRE(test_sink->lines()[1] == "Skipped 2 duplicate messages.."); REQUIRE(test_sink->lines()[1] == "Skipped 2 duplicate messages..");
} }

View File

@ -29,8 +29,8 @@ static void test_single_print(std::function<void(std::string const &)> do_log, s
REQUIRE(event_log.handle_); REQUIRE(event_log.handle_);
DWORD read_bytes{}, size_needed{}; DWORD read_bytes{}, size_needed{};
auto ok = auto ok = ::ReadEventLogA(
::ReadEventLogA(event_log.handle_, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, 0, &read_bytes, 0, &read_bytes, &size_needed); event_log.handle_, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, 0, &read_bytes, 0, &read_bytes, &size_needed);
REQUIRE(!ok); REQUIRE(!ok);
REQUIRE(::GetLastError() == ERROR_INSUFFICIENT_BUFFER); REQUIRE(::GetLastError() == ERROR_INSUFFICIENT_BUFFER);

View File

@ -64,7 +64,8 @@ TEST_CASE("file_helper_reopen2", "[file_helper::reopen(false)]]")
REQUIRE(helper.size() == expected_size); REQUIRE(helper.size() == expected_size);
} }
static void test_split_ext(const spdlog::filename_t::value_type *fname, const spdlog::filename_t::value_type *expect_base, const spdlog::filename_t::value_type *expect_ext) static void test_split_ext(const spdlog::filename_t::value_type *fname, const spdlog::filename_t::value_type *expect_base,
const spdlog::filename_t::value_type *expect_ext)
{ {
spdlog::filename_t filename(fname); spdlog::filename_t filename(fname);
spdlog::filename_t expected_base(expect_base); spdlog::filename_t expected_base(expect_base);