mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-26 02:21:34 +08:00
Clang format
This commit is contained in:
parent
25b3f61b24
commit
8e1837a4f1
@ -1,4 +1,4 @@
|
|||||||
//
|
//
|
||||||
// Copyright(c) 2015 Gabi Melman.
|
// Copyright(c) 2015 Gabi Melman.
|
||||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
@ -173,6 +173,7 @@ void trace_example() {
|
|||||||
|
|
||||||
// stopwatch example
|
// stopwatch example
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "spdlog/stopwatch.h"
|
#include "spdlog/stopwatch.h"
|
||||||
void stopwatch_example() {
|
void stopwatch_example() {
|
||||||
spdlog::stopwatch sw;
|
spdlog::stopwatch sw;
|
||||||
@ -227,7 +228,7 @@ void err_handler_example() {
|
|||||||
|
|
||||||
// syslog example (linux/osx/freebsd)
|
// syslog example (linux/osx/freebsd)
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include "spdlog/sinks/syslog_sink.h"
|
#include "spdlog/sinks/syslog_sink.h"
|
||||||
void syslog_example() {
|
void syslog_example() {
|
||||||
std::string ident = "spdlog-example";
|
std::string ident = "spdlog-example";
|
||||||
auto syslog_logger = spdlog::syslog_logger_mt("syslog", ident, LOG_PID);
|
auto syslog_logger = spdlog::syslog_logger_mt("syslog", ident, LOG_PID);
|
||||||
@ -237,7 +238,7 @@ void syslog_example() {
|
|||||||
|
|
||||||
// Android example.
|
// Android example.
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
#include "spdlog/sinks/android_sink.h"
|
#include "spdlog/sinks/android_sink.h"
|
||||||
void android_example() {
|
void android_example() {
|
||||||
std::string tag = "spdlog-android";
|
std::string tag = "spdlog-android";
|
||||||
auto android_logger = spdlog::android_logger_mt("android", tag);
|
auto android_logger = spdlog::android_logger_mt("android", tag);
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <chrono>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <chrono>
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
#include "./source_loc.h"
|
#include "./source_loc.h"
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <ctime> // std::time_t
|
#include <ctime> // std::time_t
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
#include "../filename_t.h"
|
#include "../filename_t.h"
|
||||||
|
|
||||||
@ -66,7 +67,6 @@ SPDLOG_API void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target);
|
|||||||
SPDLOG_API void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target);
|
SPDLOG_API void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// non thread safe, cross platform getenv/getenv_s
|
// non thread safe, cross platform getenv/getenv_s
|
||||||
// return empty string if field not found
|
// return empty string if field not found
|
||||||
SPDLOG_API std::string getenv(const char *field);
|
SPDLOG_API std::string getenv(const char *field);
|
||||||
@ -106,7 +106,6 @@ SPDLOG_API bool rename(const filename_t &filename1, const filename_t &filename2)
|
|||||||
// Return if file exists.
|
// Return if file exists.
|
||||||
SPDLOG_API bool path_exists(const filename_t &filename) noexcept;
|
SPDLOG_API bool path_exists(const filename_t &filename) noexcept;
|
||||||
|
|
||||||
|
|
||||||
// Return file path and its extension:
|
// Return file path and its extension:
|
||||||
//
|
//
|
||||||
// "mylog.txt" => ("mylog", ".txt")
|
// "mylog.txt" => ("mylog", ".txt")
|
||||||
@ -124,7 +123,6 @@ SPDLOG_API std::tuple<filename_t, filename_t> split_by_extension(const filename_
|
|||||||
// Try tp convert filename to string. Return "??" if failed
|
// Try tp convert filename to string. Return "??" if failed
|
||||||
SPDLOG_API std::string filename_to_str(const filename_t &filename);
|
SPDLOG_API std::string filename_to_str(const filename_t &filename);
|
||||||
|
|
||||||
|
|
||||||
} // namespace os
|
} // namespace os
|
||||||
} // namespace details
|
} // namespace details
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "./filename_t.h"
|
#include "./filename_t.h"
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
|
@ -11,13 +11,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
#include "./base_sink.h"
|
|
||||||
#include "../details/circular_q.h"
|
#include "../details/circular_q.h"
|
||||||
#include "../details/file_helper.h"
|
#include "../details/file_helper.h"
|
||||||
#include "../details/null_mutex.h"
|
#include "../details/null_mutex.h"
|
||||||
#include "../details/os.h"
|
#include "../details/os.h"
|
||||||
#include "../details/synchronous_factory.h"
|
#include "../details/synchronous_factory.h"
|
||||||
|
#include "./base_sink.h"
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace sinks {
|
namespace sinks {
|
||||||
|
@ -53,7 +53,6 @@ SPDLOG_API bool should_log(level level);
|
|||||||
// Set flush level of the global logger.
|
// Set flush level of the global logger.
|
||||||
SPDLOG_API void flush_on(level level);
|
SPDLOG_API void flush_on(level level);
|
||||||
|
|
||||||
|
|
||||||
// Set error handler for the global logger
|
// Set error handler for the global logger
|
||||||
SPDLOG_API void set_error_handler(void (*handler)(const std::string &msg));
|
SPDLOG_API void set_error_handler(void (*handler)(const std::string &msg));
|
||||||
|
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
#include "spdlog/details/context.h"
|
#include "spdlog/details/context.h"
|
||||||
|
|
||||||
#include "spdlog/logger.h"
|
#include "spdlog/logger.h"
|
||||||
|
|
||||||
#ifndef SPDLOG_DISABLE_GLOBAL_LOGGER
|
#ifndef SPDLOG_DISABLE_GLOBAL_LOGGER
|
||||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||||
#endif // SPDLOG_DISABLE_GLOBAL_LOGGER
|
#endif // SPDLOG_DISABLE_GLOBAL_LOGGER
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -13,24 +14,18 @@
|
|||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace details {
|
namespace details {
|
||||||
|
|
||||||
context::context(std::unique_ptr<logger> global_logger) {
|
context::context(std::unique_ptr<logger> global_logger) { global_logger_ = std::move(global_logger); }
|
||||||
global_logger_ = std::move(global_logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<logger> context::global_logger() {
|
std::shared_ptr<logger> context::global_logger() { return global_logger_; }
|
||||||
return global_logger_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return raw ptr to the global logger.
|
// Return raw ptr to the global logger.
|
||||||
// To be used directly by the spdlog default api (e.g. spdlog::info)
|
// To be used directly by the spdlog default api (e.g. spdlog::info)
|
||||||
// This make the default API faster, but cannot be used concurrently with set_global_logger().
|
// This make the default API faster, but cannot be used concurrently with set_global_logger().
|
||||||
// e.g do not call set_global_logger() from one thread while calling spdlog::info() from another.
|
// e.g do not call set_global_logger() from one thread while calling spdlog::info() from another.
|
||||||
logger *context::global_logger_raw() const noexcept{ return global_logger_.get(); }
|
logger *context::global_logger_raw() const noexcept { return global_logger_.get(); }
|
||||||
|
|
||||||
// set global logger
|
// set global logger
|
||||||
void context::set_logger(std::shared_ptr<logger> new_global_logger) {
|
void context::set_logger(std::shared_ptr<logger> new_global_logger) { global_logger_ = std::move(new_global_logger); }
|
||||||
global_logger_ = std::move(new_global_logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
void context::set_tp(std::shared_ptr<thread_pool> tp) {
|
void context::set_tp(std::shared_ptr<thread_pool> tp) {
|
||||||
std::lock_guard lock(tp_mutex_);
|
std::lock_guard lock(tp_mutex_);
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
|
#include "spdlog/details/file_helper.h"
|
||||||
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <utility>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "spdlog/details/file_helper.h"
|
|
||||||
#include "spdlog/common.h"
|
#include "spdlog/common.h"
|
||||||
#include "spdlog/details/os.h"
|
#include "spdlog/details/os.h"
|
||||||
|
|
||||||
@ -110,6 +110,5 @@ size_t file_helper::size() const {
|
|||||||
|
|
||||||
const filename_t &file_helper::filename() const { return filename_; }
|
const filename_t &file_helper::filename() const { return filename_; }
|
||||||
|
|
||||||
|
|
||||||
} // namespace details
|
} // namespace details
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
||||||
|
@ -11,9 +11,7 @@ namespace spdlog {
|
|||||||
namespace details {
|
namespace details {
|
||||||
namespace os {
|
namespace os {
|
||||||
|
|
||||||
bool remove(const filename_t &filename) {
|
bool remove(const filename_t &filename) { return std::filesystem::remove(filename); }
|
||||||
return std::filesystem::remove(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool remove_if_exists(const filename_t &filename) {
|
bool remove_if_exists(const filename_t &filename) {
|
||||||
if (path_exists(filename)) {
|
if (path_exists(filename)) {
|
||||||
|
@ -99,7 +99,6 @@ bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode) {
|
|||||||
return *fp == nullptr;
|
return *fp == nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Return file size according to open FILE* object
|
// Return file size according to open FILE* object
|
||||||
size_t filesize(FILE *f) {
|
size_t filesize(FILE *f) {
|
||||||
if (f == nullptr) {
|
if (f == nullptr) {
|
||||||
|
@ -75,8 +75,6 @@ bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode) {
|
|||||||
return *fp == nullptr;
|
return *fp == nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
// avoid warning about unreachable statement at the end of filesize()
|
// avoid warning about unreachable statement at the end of filesize()
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
@ -155,11 +153,9 @@ std::string filename_to_str(const filename_t &filename) {
|
|||||||
memory_buf_t buf;
|
memory_buf_t buf;
|
||||||
wstr_to_utf8buf(filename.wstring(), buf);
|
wstr_to_utf8buf(filename.wstring(), buf);
|
||||||
return std::string(buf.data(), buf.size());
|
return std::string(buf.data(), buf.size());
|
||||||
}
|
} catch (...) {
|
||||||
catch (...) {
|
|
||||||
return "???";
|
return "???";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int pid() noexcept { return static_cast<int>(::GetCurrentProcessId()); }
|
int pid() noexcept { return static_cast<int>(::GetCurrentProcessId()); }
|
||||||
@ -224,7 +220,6 @@ void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) {
|
|||||||
throw_spdlog_ex(fmt_lib::format("MultiByteToWideChar failed. Last error: {}", ::GetLastError()));
|
throw_spdlog_ex(fmt_lib::format("MultiByteToWideChar failed. Last error: {}", ::GetLastError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string getenv(const char *field) {
|
std::string getenv(const char *field) {
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#if defined(__cplusplus_winrt)
|
#if defined(__cplusplus_winrt)
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "spdlog/common.h"
|
#include "spdlog/common.h"
|
||||||
#include "spdlog/details/file_helper.h"
|
#include "spdlog/details/file_helper.h"
|
||||||
@ -132,7 +132,7 @@ void rotating_file_sink<Mutex>::rotate_() {
|
|||||||
// delete the target if exists, and rename the src file to target
|
// delete the target if exists, and rename the src file to target
|
||||||
// return true on success, false otherwise.
|
// return true on success, false otherwise.
|
||||||
template <typename Mutex>
|
template <typename Mutex>
|
||||||
bool rotating_file_sink<Mutex>::rename_file_(const filename_t &src_filename, const filename_t &target_filename) noexcept{
|
bool rotating_file_sink<Mutex>::rename_file_(const filename_t &src_filename, const filename_t &target_filename) noexcept {
|
||||||
return details::os::rename(src_filename, target_filename);
|
return details::os::rename(src_filename, target_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "spdlog/common.h"
|
#include "spdlog/common.h"
|
||||||
#include "spdlog/logger.h"
|
#include "spdlog/logger.h"
|
||||||
#include "spdlog/pattern_formatter.h"
|
#include "spdlog/pattern_formatter.h"
|
||||||
@ -21,15 +22,13 @@ static std::shared_ptr s_context =
|
|||||||
|
|
||||||
void set_context(std::shared_ptr<details::context> context) { s_context = std::move(context); }
|
void set_context(std::shared_ptr<details::context> context) { s_context = std::move(context); }
|
||||||
|
|
||||||
std::shared_ptr<details::context> context() {return s_context;}
|
std::shared_ptr<details::context> context() { return s_context; }
|
||||||
|
|
||||||
const std::shared_ptr<details::context> &context_ref() {return s_context;}
|
const std::shared_ptr<details::context> &context_ref() { return s_context; }
|
||||||
|
|
||||||
std::shared_ptr<logger> global_logger() { return context_ref()->global_logger(); }
|
std::shared_ptr<logger> global_logger() { return context_ref()->global_logger(); }
|
||||||
|
|
||||||
void set_global_logger(std::shared_ptr<logger> global_logger) {
|
void set_global_logger(std::shared_ptr<logger> global_logger) { context()->set_logger(std::move(global_logger)); }
|
||||||
context()->set_logger(std::move(global_logger));
|
|
||||||
}
|
|
||||||
|
|
||||||
logger *global_logger_raw() noexcept {
|
logger *global_logger_raw() noexcept {
|
||||||
auto *rv = context_ref()->global_logger_raw();
|
auto *rv = context_ref()->global_logger_raw();
|
||||||
@ -37,9 +36,7 @@ logger *global_logger_raw() noexcept {
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_formatter(std::unique_ptr<formatter> formatter) {
|
void set_formatter(std::unique_ptr<formatter> formatter) { global_logger()->set_formatter(std::move(formatter)); }
|
||||||
global_logger()->set_formatter(std::move(formatter));
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_pattern(std::string pattern, pattern_time_type time_type) {
|
void set_pattern(std::string pattern, pattern_time_type time_type) {
|
||||||
set_formatter(std::make_unique<pattern_formatter>(std::move(pattern), time_type));
|
set_formatter(std::make_unique<pattern_formatter>(std::move(pattern), time_type));
|
||||||
@ -55,7 +52,6 @@ void flush_on(level level) { global_logger()->flush_on(level); }
|
|||||||
|
|
||||||
void set_error_handler(void (*handler)(const std::string &msg)) { global_logger()->set_error_handler(handler); }
|
void set_error_handler(void (*handler)(const std::string &msg)) { global_logger()->set_error_handler(handler); }
|
||||||
|
|
||||||
void shutdown() { s_context.reset();}
|
void shutdown() { s_context.reset(); }
|
||||||
|
|
||||||
|
|
||||||
} // namespace spdlog
|
} // namespace spdlog
|
||||||
|
@ -88,7 +88,6 @@ TEST_CASE("flush", "[async]") {
|
|||||||
REQUIRE(test_sink->flush_counter() == 1);
|
REQUIRE(test_sink->flush_counter() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("tp->wait_empty() ", "[async]") {
|
TEST_CASE("tp->wait_empty() ", "[async]") {
|
||||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
auto test_sink = std::make_shared<spdlog::sinks::test_sink_mt>();
|
||||||
test_sink->set_delay(std::chrono::milliseconds(5));
|
test_sink->set_delay(std::chrono::milliseconds(5));
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
#include "spdlog/sinks/daily_file_sink.h"
|
#include "spdlog/sinks/daily_file_sink.h"
|
||||||
#include "spdlog/sinks/rotating_file_sink.h"
|
|
||||||
#include "spdlog/sinks/hourly_file_sink.h"
|
#include "spdlog/sinks/hourly_file_sink.h"
|
||||||
|
#include "spdlog/sinks/rotating_file_sink.h"
|
||||||
|
|
||||||
using filename_memory_buf_t = spdlog::memory_buf_t;
|
using filename_memory_buf_t = spdlog::memory_buf_t;
|
||||||
|
|
||||||
@ -48,8 +48,7 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger]") {
|
|||||||
std::tm tm = spdlog::details::os::localtime();
|
std::tm tm = spdlog::details::os::localtime();
|
||||||
|
|
||||||
auto w = spdlog::fmt_lib::format(SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename.native(), tm.tm_year + 1900,
|
auto w = spdlog::fmt_lib::format(SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename.native(), tm.tm_year + 1900,
|
||||||
tm.tm_mon + 1,
|
tm.tm_mon + 1, tm.tm_mday);
|
||||||
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) {
|
||||||
@ -82,13 +81,12 @@ TEST_CASE("rotating_file_sink::calc_filename3", "[rotating_file_sink]") {
|
|||||||
// regex supported only from gcc 4.9 and above
|
// regex supported only from gcc 4.9 and above
|
||||||
#if defined(_MSC_VER) || !(__GNUC__ <= 4 && __GNUC_MINOR__ < 9)
|
#if defined(_MSC_VER) || !(__GNUC__ <= 4 && __GNUC_MINOR__ < 9)
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
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 =
|
auto filename =
|
||||||
spdlog::sinks::daily_filename_calculator::calc_filename(SPDLOG_FILENAME_T("daily.txt"),
|
spdlog::sinks::daily_filename_calculator::calc_filename(SPDLOG_FILENAME_T("daily.txt"), spdlog::details::os::localtime());
|
||||||
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(
|
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$)"));
|
SPDLOG_FILENAME_T(R"(^daily_(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])\.txt$)"));
|
||||||
@ -97,11 +95,10 @@ TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]") {
|
|||||||
REQUIRE(std::regex_match(filename.native(), match, re));
|
REQUIRE(std::regex_match(filename.native(), match, re));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("hourly_file_sink::hourly_filename_calculator", "[hrouly_file_sink]") {
|
TEST_CASE("hourly_file_sink::hourly_filename_calculator", "[hrouly_file_sink]") {
|
||||||
// daily_YYYY-MM-DD_hh-mm.txt
|
// daily_YYYY-MM-DD_hh-mm.txt
|
||||||
auto filename =
|
auto filename = spdlog::sinks::hourly_filename_calculator::calc_filename(SPDLOG_FILENAME_T("hourly.txt"),
|
||||||
spdlog::sinks::hourly_filename_calculator::calc_filename(SPDLOG_FILENAME_T("hourly.txt"), spdlog::details::os::localtime());
|
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(
|
std::basic_regex<spdlog::filename_t::value_type> re(
|
||||||
SPDLOG_FILENAME_T(R"(^hourly_(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])_\d\d\.txt$)"));
|
SPDLOG_FILENAME_T(R"(^hourly_(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])_\d\d\.txt$)"));
|
||||||
|
@ -44,7 +44,6 @@ TEST_CASE("custom_error_handler", "[errors]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("default_error_handler2", "[errors]") {
|
TEST_CASE("default_error_handler2", "[errors]") {
|
||||||
|
|
||||||
auto logger = std::make_shared<spdlog::logger>("failed_logger", std::make_shared<failing_sink>());
|
auto logger = std::make_shared<spdlog::logger>("failed_logger", std::make_shared<failing_sink>());
|
||||||
logger->set_error_handler([=](const std::string &) { throw custom_ex(); });
|
logger->set_error_handler([=](const std::string &) { throw custom_ex(); });
|
||||||
REQUIRE_THROWS_AS(logger->info("Some message"), custom_ex);
|
REQUIRE_THROWS_AS(logger->info("Some message"), custom_ex);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <string>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
std::size_t count_files(const std::string &folder);
|
std::size_t count_files(const std::string &folder);
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ void prepare_logdir();
|
|||||||
|
|
||||||
std::string file_contents(const std::string &filename);
|
std::string file_contents(const std::string &filename);
|
||||||
|
|
||||||
//std::size_t count_lines(const std::string &filename);
|
// std::size_t count_lines(const std::string &filename);
|
||||||
std::size_t count_lines(const std::filesystem::path &filename);
|
std::size_t count_lines(const std::filesystem::path &filename);
|
||||||
|
|
||||||
void require_message_count(const std::filesystem::path &filename, const std::size_t messages);
|
void require_message_count(const std::filesystem::path &filename, const std::size_t messages);
|
||||||
|
Loading…
Reference in New Issue
Block a user