mirror of
https://github.com/gabime/spdlog.git
synced 2025-04-29 12:03:53 +00:00
Merge PR #3366 from 1.x (Fix zformatter on Apple and POSIX.1-2024 conforming platform)
This commit is contained in:
parent
1b0a1dda33
commit
22122f3901
@ -129,8 +129,10 @@ size_t filesize(FILE *f) {
|
|||||||
|
|
||||||
// Return utc offset in minutes or throw spdlog_ex on failure
|
// Return utc offset in minutes or throw spdlog_ex on failure
|
||||||
int utc_minutes_offset(const std::tm &tm) {
|
int utc_minutes_offset(const std::tm &tm) {
|
||||||
#if defined(sun) || defined(__sun) || defined(_AIX) || (defined(__NEWLIB__) && !defined(__TM_GMTOFF)) || \
|
#if defined(sun) || defined(__sun) || defined(_AIX) || \
|
||||||
(!defined(_BSD_SOURCE) && !defined(_GNU_SOURCE))
|
(defined(__NEWLIB__) && !defined(__TM_GMTOFF)) || \
|
||||||
|
(!defined(__APPLE__) && !defined(_BSD_SOURCE) && !defined(_GNU_SOURCE) && \
|
||||||
|
(!defined(_POSIX_VERSION) || (_POSIX_VERSION < 202405L)))
|
||||||
// 'tm_gmtoff' field is BSD extension and it's missing on SunOS/Solaris
|
// 'tm_gmtoff' field is BSD extension and it's missing on SunOS/Solaris
|
||||||
struct helper {
|
struct helper {
|
||||||
static long int calculate_gmt_offset(const std::tm &localtm = details::os::localtime(),
|
static long int calculate_gmt_offset(const std::tm &localtm = details::os::localtime(),
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
#include "spdlog/sinks/ostream_sink.h"
|
#include "spdlog/sinks/ostream_sink.h"
|
||||||
#include "test_sink.h"
|
#include "test_sink.h"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
using spdlog::memory_buf_t;
|
using spdlog::memory_buf_t;
|
||||||
|
|
||||||
// log to str and return it
|
// log to str and return it
|
||||||
@ -18,6 +20,21 @@ static std::string log_to_str(const std::string &msg, const Args &...args) {
|
|||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// log to str and return it with time
|
||||||
|
template <typename... Args>
|
||||||
|
static std::string log_to_str_with_time(spdlog::log_clock::time_point log_time, const std::string &msg, const Args &...args) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
||||||
|
spdlog::logger oss_logger("pattern_tester", oss_sink);
|
||||||
|
oss_logger.set_level(spdlog::level::info);
|
||||||
|
|
||||||
|
oss_logger.set_formatter(
|
||||||
|
std::unique_ptr<spdlog::formatter>(new spdlog::pattern_formatter(args...)));
|
||||||
|
|
||||||
|
oss_logger.log(log_time, {}, spdlog::level::info, msg);
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("custom eol", "[pattern_formatter]") {
|
TEST_CASE("custom eol", "[pattern_formatter]") {
|
||||||
std::string msg = "Hello custom eol test";
|
std::string msg = "Hello custom eol test";
|
||||||
std::string eol = ";)";
|
std::string eol = ";)";
|
||||||
@ -52,6 +69,15 @@ TEST_CASE("date MM/DD/YY ", "[pattern_formatter]") {
|
|||||||
REQUIRE(log_to_str("Some message", "%D %v", spdlog::pattern_time_type::local, "\n") == oss.str());
|
REQUIRE(log_to_str("Some message", "%D %v", spdlog::pattern_time_type::local, "\n") == oss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("GMT offset ", "[pattern_formatter]") {
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
const auto now = std::chrono::system_clock::now();
|
||||||
|
const auto yesterday = now - 24h;
|
||||||
|
|
||||||
|
REQUIRE(log_to_str_with_time(yesterday, "Some message", "%z", spdlog::pattern_time_type::utc, "\n") ==
|
||||||
|
"+00:00\n");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("color range test1", "[pattern_formatter]") {
|
TEST_CASE("color range test1", "[pattern_formatter]") {
|
||||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^%v%$", spdlog::pattern_time_type::local, "\n");
|
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^%v%$", spdlog::pattern_time_type::local, "\n");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user