mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 08:25:43 +08:00
clang-format
This commit is contained in:
parent
e98265a49b
commit
e7e8b75a4c
@ -100,14 +100,14 @@ if (WIN32)
|
||||
option(SPDLOG_WCHAR_SUPPORT "Support wchar api" OFF)
|
||||
option(SPDLOG_WCHAR_FILENAMES "Support wchar filenames" OFF)
|
||||
else()
|
||||
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_SUPPORT OFF CACHE BOOL "non supported option" FORCE)
|
||||
set(SPDLOG_WCHAR_FILENAMES OFF CACHE BOOL "non supported option" FORCE)
|
||||
endif()
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||
option(SPDLOG_CLOCK_COARSE "Use CLOCK_REALTIME_COARSE instead of the regular clock," OFF)
|
||||
else()
|
||||
SET(SPDLOG_CLOCK_COARSE OFF CACHE BOOL "non supported option" FORCE)
|
||||
set(SPDLOG_CLOCK_COARSE OFF CACHE BOOL "non supported option" FORCE)
|
||||
endif()
|
||||
|
||||
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})
|
||||
target_compile_definitions(spdlog PUBLIC SPDLOG_SHARED_LIB)
|
||||
if(MSVC)
|
||||
target_compile_options(spdlog PUBLIC
|
||||
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<NOT:$<COMPILE_LANGUAGE:CUDA>>>:/wd4251 /wd4275>)
|
||||
target_compile_options(spdlog PUBLIC $<$<AND:$<CXX_COMPILER_ID:MSVC>,$<NOT:$<COMPILE_LANGUAGE:CUDA>>>:/wd4251
|
||||
/wd4275>)
|
||||
endif()
|
||||
if(NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
|
||||
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)
|
||||
endif()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Build binaries
|
||||
# ---------------------------------------------------------------------------------------
|
||||
@ -318,4 +317,3 @@ if (SPDLOG_INSTALL)
|
||||
# ---------------------------------------------------------------------------------------
|
||||
include(cmake/spdlogCPack.cmake)
|
||||
endif()
|
||||
|
||||
|
@ -18,9 +18,7 @@ if (NOT benchmark_FOUND)
|
||||
include(FetchContent)
|
||||
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE INTERNAL "")
|
||||
# Do not build and run googlebenchmark tests
|
||||
FetchContent_Declare(googlebenchmark
|
||||
GIT_REPOSITORY https://github.com/google/benchmark.git
|
||||
GIT_TAG v1.5.2)
|
||||
FetchContent_Declare(googlebenchmark GIT_REPOSITORY https://github.com/google/benchmark.git GIT_TAG v1.5.2)
|
||||
|
||||
FetchContent_MakeAvailable(googlebenchmark)
|
||||
else()
|
||||
|
@ -60,4 +60,3 @@ function(spdlog_enable_sanitizer target_name)
|
||||
target_compile_options(${target_name} PRIVATE -fno-omit-frame-pointer)
|
||||
target_link_libraries(${target_name} PRIVATE -fsanitize=address,undefined -fuse-ld=gold)
|
||||
endfunction()
|
||||
|
||||
|
@ -43,4 +43,3 @@ public:
|
||||
#ifdef SPDLOG_HEADER_ONLY
|
||||
# include "backtracer-inl.h"
|
||||
#endif
|
||||
|
||||
|
@ -26,9 +26,7 @@ SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg_buffer &other)
|
||||
update_string_views();
|
||||
}
|
||||
|
||||
SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT
|
||||
: log_msg{other}
|
||||
, buffer{std::move(other.buffer)}
|
||||
SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT : log_msg{other}, buffer{std::move(other.buffer)}
|
||||
{
|
||||
update_string_views();
|
||||
}
|
||||
|
@ -22,4 +22,3 @@ struct synchronous_factory
|
||||
}
|
||||
};
|
||||
} // namespace spdlog
|
||||
|
||||
|
@ -25,4 +25,3 @@
|
||||
# include <fmt/core.h>
|
||||
# include <fmt/format.h>
|
||||
#endif
|
||||
|
||||
|
@ -56,4 +56,3 @@ inline std::shared_ptr<logger> basic_logger_st(const std::string &logger_name, c
|
||||
#ifdef SPDLOG_HEADER_ONLY
|
||||
# include "basic_file_sink-inl.h"
|
||||
#endif
|
||||
|
||||
|
@ -31,8 +31,8 @@ struct hourly_filename_calculator
|
||||
{
|
||||
filename_t basename, ext;
|
||||
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
|
||||
return fmt::format(
|
||||
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);
|
||||
return fmt::format(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);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -25,34 +25,41 @@
|
||||
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
template <typename Mutex> class mongo_sink : public base_sink<Mutex> {
|
||||
template<typename Mutex>
|
||||
class mongo_sink : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
mongo_sink(const std::string &db_name, const std::string &collection_name,
|
||||
const std::string &uri = "mongodb://localhost:27017") {
|
||||
try {
|
||||
mongo_sink(const std::string &db_name, const std::string &collection_name, const std::string &uri = "mongodb://localhost:27017")
|
||||
{
|
||||
try
|
||||
{
|
||||
client_ = std::make_unique<mongocxx::client>(mongocxx::uri{uri});
|
||||
db_name_ = db_name;
|
||||
coll_name_ = collection_name;
|
||||
} catch (const std::exception) {
|
||||
}
|
||||
catch (const std::exception)
|
||||
{
|
||||
throw spdlog_ex("Error opening database");
|
||||
}
|
||||
}
|
||||
|
||||
~mongo_sink() { flush_(); }
|
||||
~mongo_sink()
|
||||
{
|
||||
flush_();
|
||||
}
|
||||
|
||||
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::finalize;
|
||||
|
||||
if (client_ != nullptr) {
|
||||
auto doc = document{}
|
||||
<< "timestamp" << bsoncxx::types::b_date(msg.time) << "level"
|
||||
<< level::to_string_view(msg.level).data() << "message"
|
||||
<< std::string(msg.payload.begin(), msg.payload.end())
|
||||
<< "logger_name"
|
||||
<< std::string(msg.logger_name.begin(), msg.logger_name.end())
|
||||
<< "thread_id" << static_cast<int>(msg.thread_id) << finalize;
|
||||
if (client_ != nullptr)
|
||||
{
|
||||
auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level" << level::to_string_view(msg.level).data()
|
||||
<< "message" << std::string(msg.payload.begin(), msg.payload.end()) << "logger_name"
|
||||
<< 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());
|
||||
}
|
||||
}
|
||||
@ -75,22 +82,17 @@ using mongo_sink_st = mongo_sink<spdlog::details::null_mutex>;
|
||||
} // namespace sinks
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
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") {
|
||||
return Factory::template create<sinks::mongo_sink_mt>(logger_name, db_name,
|
||||
collection_name, uri);
|
||||
inline std::shared_ptr<logger> 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")
|
||||
{
|
||||
return Factory::template create<sinks::mongo_sink_mt>(logger_name, db_name, collection_name, uri);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
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") {
|
||||
return Factory::template create<sinks::mongo_sink_st>(logger_name, db_name,
|
||||
collection_name, uri);
|
||||
inline std::shared_ptr<logger> 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")
|
||||
{
|
||||
return Factory::template create<sinks::mongo_sink_st>(logger_name, db_name, collection_name, uri);
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
|
||||
|
@ -11,7 +11,6 @@
|
||||
# include <mutex>
|
||||
# include <string>
|
||||
|
||||
|
||||
// Avoid including windows.h (https://stackoverflow.com/a/30741042)
|
||||
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString);
|
||||
|
||||
|
@ -22,22 +22,24 @@ namespace _sinks_p {
|
||||
//
|
||||
// Private class for QTextEdit and its derivatives
|
||||
//
|
||||
class qtextedit_sink_p : public QObject {
|
||||
class qtextedit_sink_p : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
qtextedit_sink_p(QTextEdit *textedit = nullptr) {
|
||||
if (textedit != nullptr) {
|
||||
qtextedit_sink_p(QTextEdit *textedit = nullptr)
|
||||
{
|
||||
if (textedit != nullptr)
|
||||
{
|
||||
textedit_ = textedit;
|
||||
connect(this, &qtextedit_sink_p::append_text, textedit_,
|
||||
&QTextEdit::append);
|
||||
connect(this, &qtextedit_sink_p::append_text, textedit_, &QTextEdit::append);
|
||||
}
|
||||
}
|
||||
|
||||
~qtextedit_sink_p() {}
|
||||
|
||||
void append(const spdlog::string_view_t &str) {
|
||||
emit append_text(
|
||||
QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
|
||||
void append(const spdlog::string_view_t &str)
|
||||
{
|
||||
emit append_text(QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
|
||||
}
|
||||
|
||||
signals:
|
||||
@ -50,22 +52,24 @@ private:
|
||||
//
|
||||
// Private class for QPlainTextEdit
|
||||
//
|
||||
class qplaintextedit_sink_p : public QObject {
|
||||
class qplaintextedit_sink_p : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
qplaintextedit_sink_p(QPlainTextEdit *textedit = nullptr) {
|
||||
if (textedit != nullptr) {
|
||||
qplaintextedit_sink_p(QPlainTextEdit *textedit = nullptr)
|
||||
{
|
||||
if (textedit != nullptr)
|
||||
{
|
||||
textedit_ = textedit;
|
||||
connect(this, &qplaintextedit_sink_p::append_text, textedit_,
|
||||
&QPlainTextEdit::appendPlainText);
|
||||
connect(this, &qplaintextedit_sink_p::append_text, textedit_, &QPlainTextEdit::appendPlainText);
|
||||
}
|
||||
}
|
||||
|
||||
~qplaintextedit_sink_p() {}
|
||||
|
||||
void append(const spdlog::string_view_t &str) {
|
||||
emit append_text(
|
||||
QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
|
||||
void append(const spdlog::string_view_t &str)
|
||||
{
|
||||
emit append_text(QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
|
||||
}
|
||||
|
||||
signals:
|
||||
@ -82,21 +86,30 @@ private:
|
||||
//
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
template <typename Mutex> class qtextedit_sink : public base_sink<Mutex> {
|
||||
template<typename Mutex>
|
||||
class qtextedit_sink : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
qtextedit_sink(QTextEdit *textedit = nullptr) {
|
||||
if (textedit != nullptr) {
|
||||
textedit_p =
|
||||
std::make_shared<_spdlog_p::_sinks_p::qtextedit_sink_p>(textedit);
|
||||
} else {
|
||||
qtextedit_sink(QTextEdit *textedit = nullptr)
|
||||
{
|
||||
if (textedit != nullptr)
|
||||
{
|
||||
textedit_p = std::make_shared<_spdlog_p::_sinks_p::qtextedit_sink_p>(textedit);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw spdlog_ex("Error opening QTextEdit");
|
||||
}
|
||||
}
|
||||
|
||||
~qtextedit_sink() { flush_(); }
|
||||
~qtextedit_sink()
|
||||
{
|
||||
flush_();
|
||||
}
|
||||
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override {
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
string_view_t str_v = string_view_t(formatted.data(), formatted.size());
|
||||
@ -112,21 +125,30 @@ private:
|
||||
//
|
||||
// qplaintextedit_sink class
|
||||
//
|
||||
template <typename Mutex> class qplaintextedit_sink : public base_sink<Mutex> {
|
||||
template<typename Mutex>
|
||||
class qplaintextedit_sink : public base_sink<Mutex>
|
||||
{
|
||||
public:
|
||||
qplaintextedit_sink(QPlainTextEdit *textedit = nullptr) {
|
||||
if (textedit != nullptr) {
|
||||
textedit_p = std::make_shared<_spdlog_p::_sinks_p::qplaintextedit_sink_p>(
|
||||
textedit);
|
||||
} else {
|
||||
qplaintextedit_sink(QPlainTextEdit *textedit = nullptr)
|
||||
{
|
||||
if (textedit != nullptr)
|
||||
{
|
||||
textedit_p = std::make_shared<_spdlog_p::_sinks_p::qplaintextedit_sink_p>(textedit);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw spdlog_ex("Error opening QPlainTextEdit");
|
||||
}
|
||||
}
|
||||
|
||||
~qplaintextedit_sink() { flush_(); }
|
||||
~qplaintextedit_sink()
|
||||
{
|
||||
flush_();
|
||||
}
|
||||
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override {
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
string_view_t str_v = string_view_t(formatted.data(), formatted.size());
|
||||
@ -136,8 +158,7 @@ protected:
|
||||
void flush_() override {}
|
||||
|
||||
private:
|
||||
std::shared_ptr<_spdlog_p::_sinks_p::qplaintextedit_sink_p> textedit_p =
|
||||
nullptr;
|
||||
std::shared_ptr<_spdlog_p::_sinks_p::qplaintextedit_sink_p> textedit_p = nullptr;
|
||||
};
|
||||
|
||||
#include "spdlog/details/null_mutex.h"
|
||||
@ -154,34 +175,26 @@ using qplaintextedit_sink_st = qplaintextedit_sink<spdlog::details::null_mutex>;
|
||||
// Factory functions
|
||||
//
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qtextedit_logger_mt(const std::string &logger_name,
|
||||
QTextEdit *qtextedit = nullptr) {
|
||||
return Factory::template create<sinks::qtextedit_sink_mt>(logger_name,
|
||||
qtextedit);
|
||||
inline std::shared_ptr<logger> qtextedit_logger_mt(const std::string &logger_name, QTextEdit *qtextedit = nullptr)
|
||||
{
|
||||
return Factory::template create<sinks::qtextedit_sink_mt>(logger_name, qtextedit);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qtextedit_logger_st(const std::string &logger_name,
|
||||
QTextEdit *qtextedit = nullptr) {
|
||||
return Factory::template create<sinks::qtextedit_sink_st>(logger_name,
|
||||
qtextedit);
|
||||
inline std::shared_ptr<logger> qtextedit_logger_st(const std::string &logger_name, QTextEdit *qtextedit = nullptr)
|
||||
{
|
||||
return Factory::template create<sinks::qtextedit_sink_st>(logger_name, qtextedit);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qplaintextedit_logger_mt(const std::string &logger_name,
|
||||
QPlainTextEdit *qplaintextedit = nullptr) {
|
||||
return Factory::template create<sinks::qplaintextedit_sink_mt>(
|
||||
logger_name, qplaintextedit);
|
||||
inline std::shared_ptr<logger> qplaintextedit_logger_mt(const std::string &logger_name, QPlainTextEdit *qplaintextedit = nullptr)
|
||||
{
|
||||
return Factory::template create<sinks::qplaintextedit_sink_mt>(logger_name, qplaintextedit);
|
||||
}
|
||||
|
||||
template<typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qplaintextedit_logger_st(const std::string &logger_name,
|
||||
QPlainTextEdit *qplaintextedit = nullptr) {
|
||||
return Factory::template create<sinks::qplaintextedit_sink_st>(
|
||||
logger_name, qplaintextedit);
|
||||
inline std::shared_ptr<logger> qplaintextedit_logger_st(const std::string &logger_name, QPlainTextEdit *qplaintextedit = nullptr)
|
||||
{
|
||||
return Factory::template create<sinks::qplaintextedit_sink_st>(logger_name, qplaintextedit);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
@ -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);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
||||
|
@ -11,4 +11,3 @@
|
||||
#include <spdlog/details/thread_pool-inl.h>
|
||||
|
||||
template class SPDLOG_API spdlog::details::mpmc_blocking_queue<spdlog::details::async_msg>;
|
||||
|
||||
|
@ -6,4 +6,3 @@
|
||||
#endif
|
||||
|
||||
#include <spdlog/cfg/helpers-inl.h>
|
||||
|
||||
|
@ -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);
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_color_st<spdlog::async_factory>(
|
||||
const std::string &logger_name, color_mode mode);
|
||||
|
||||
|
@ -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>
|
||||
template class SPDLOG_API spdlog::sinks::rotating_file_sink<std::mutex>;
|
||||
template class SPDLOG_API spdlog::sinks::rotating_file_sink<spdlog::details::null_mutex>;
|
||||
|
||||
|
@ -24,4 +24,3 @@
|
||||
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<spdlog::details::null_mutex>;
|
||||
|
||||
|
@ -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::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);
|
||||
|
||||
|
@ -27,7 +27,8 @@ TEST_CASE("create_dir", "[create_dir]")
|
||||
// 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\\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")));
|
||||
#endif
|
||||
}
|
||||
|
@ -15,7 +15,8 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger]")
|
||||
spdlog::filename_t basename = SPDLOG_FILENAME_T("test_logs/daily_dateonly");
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
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);
|
||||
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)
|
||||
{
|
||||
filename_memory_buf_t w;
|
||||
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_mday);
|
||||
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_mday);
|
||||
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");
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
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);
|
||||
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]]")
|
||||
{
|
||||
// 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
|
||||
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;
|
||||
REQUIRE(std::regex_match(filename, match, re));
|
||||
}
|
||||
|
@ -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->lines()[1] == "Skipped 2 duplicate messages..");
|
||||
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ static void test_single_print(std::function<void(std::string const &)> do_log, s
|
||||
REQUIRE(event_log.handle_);
|
||||
|
||||
DWORD read_bytes{}, size_needed{};
|
||||
auto ok =
|
||||
::ReadEventLogA(event_log.handle_, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, 0, &read_bytes, 0, &read_bytes, &size_needed);
|
||||
auto ok = ::ReadEventLogA(
|
||||
event_log.handle_, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, 0, &read_bytes, 0, &read_bytes, &size_needed);
|
||||
REQUIRE(!ok);
|
||||
REQUIRE(::GetLastError() == ERROR_INSUFFICIENT_BUFFER);
|
||||
|
||||
|
@ -64,7 +64,8 @@ TEST_CASE("file_helper_reopen2", "[file_helper::reopen(false)]]")
|
||||
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 expected_base(expect_base);
|
||||
|
Loading…
Reference in New Issue
Block a user