summaryrefslogtreecommitdiff
blob: 5ee44c41ea6a5d592acc739b3024ec316e0080e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
diff --git a/include/spdlog/sinks/daily_file_sink.h b/include/spdlog/sinks/daily_file_sink.h
index f6f1bb1d..90af9676 100644
--- a/include/spdlog/sinks/daily_file_sink.h
+++ b/include/spdlog/sinks/daily_file_sink.h
@@ -13,6 +13,9 @@
 #include <spdlog/details/circular_q.h>
 #include <spdlog/details/synchronous_factory.h>
 
+#include <iostream>
+#include <sstream>
+#include <iomanip>
 #include <chrono>
 #include <cstdio>
 #include <ctime>
@@ -46,46 +49,15 @@ struct daily_filename_calculator
  */
 struct daily_filename_format_calculator
 {
-    static filename_t calc_filename(const filename_t &filename, const tm &now_tm)
+    static filename_t calc_filename(const filename_t &file_path, const tm &now_tm)
     {
-#ifdef SPDLOG_USE_STD_FORMAT
-        // adapted from fmtlib: https://github.com/fmtlib/fmt/blob/8.0.1/include/fmt/chrono.h#L522-L546
-
-        filename_t tm_format;
-        tm_format.append(filename);
-        // By appending an extra space we can distinguish an empty result that
-        // indicates insufficient buffer size from a guaranteed non-empty result
-        // https://github.com/fmtlib/fmt/issues/2238
-        tm_format.push_back(' ');
-
-        const size_t MIN_SIZE = 10;
-        filename_t buf;
-        buf.resize(MIN_SIZE);
-        for (;;)
-        {
-            size_t count = strftime(buf.data(), buf.size(), tm_format.c_str(), &now_tm);
-            if (count != 0)
-            {
-                // Remove the extra space.
-                buf.resize(count - 1);
-                break;
-            }
-            buf.resize(buf.size() * 2);
-        }
-
-        return buf;
+#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
+      std::wstringstream stream;  
 #else
-        // generate fmt datetime format string, e.g. {:%Y-%m-%d}.
-        filename_t fmt_filename = fmt::format(SPDLOG_FMT_STRING(SPDLOG_FILENAME_T("{{:{}}}")), filename);
-
-        // MSVC doesn't allow fmt::runtime(..) with wchar, with fmtlib versions < 9.1.x
-#    if defined(_MSC_VER) && defined(SPDLOG_WCHAR_FILENAMES) && FMT_VERSION < 90101
-        return fmt::format(fmt_filename, now_tm);
-#    else
-        return fmt::format(SPDLOG_FMT_RUNTIME(fmt_filename), now_tm);
-#    endif
-
+      std::stringstream stream;
 #endif
+      stream << std::put_time(&now_tm, file_path.c_str()); 
+      return stream.str();
     }
 
 private:
diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h
index 71544e84..1d802f32 100644
--- a/include/spdlog/logger.h
+++ b/include/spdlog/logger.h
@@ -369,9 +369,9 @@ protected:
         {
             memory_buf_t buf;
 #ifdef SPDLOG_USE_STD_FORMAT
-            fmt_lib::vformat_to(std::back_inserter(buf), fmt, fmt_lib::make_format_args(std::forward<Args>(args)...));
+            fmt_lib::vformat_to(std::back_inserter(buf), fmt, fmt_lib::make_format_args(args...));
 #else
-            fmt::vformat_to(fmt::appender(buf), fmt, fmt::make_format_args(std::forward<Args>(args)...));
+            fmt::vformat_to(fmt::appender(buf), fmt, fmt::make_format_args(args...));
 #endif
 
             details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size()));
@@ -395,10 +395,9 @@ protected:
             // format to wmemory_buffer and convert to utf8
             wmemory_buf_t wbuf;
 #    ifdef SPDLOG_USE_STD_FORMAT
-            fmt_lib::vformat_to(
-                std::back_inserter(wbuf), fmt, fmt_lib::make_format_args<fmt_lib::wformat_context>(std::forward<Args>(args)...));
+            fmt_lib::vformat_to(std::back_inserter(wbuf), fmt, fmt_lib::make_format_args<fmt_lib::wformat_context>(args...));
 #    else
-            fmt::vformat_to(std::back_inserter(wbuf), fmt, fmt::make_format_args<fmt::wformat_context>(std::forward<Args>(args)...));
+            fmt::vformat_to(std::back_inserter(wbuf), fmt, fmt::make_format_args<fmt::wformat_context>(args...));
 #    endif
 
             memory_buf_t buf;
diff --git a/include/spdlog/common.h b/include/spdlog/common.h
index e69201a8..5f671c5c 100644
--- a/include/spdlog/common.h
+++ b/include/spdlog/common.h
@@ -173,12 +173,19 @@ using format_string_t = fmt::format_string<Args...>;
 template<class T>
 using remove_cvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
 
+template <typename Char>
+#if FMT_VERSION >= 90101
+using fmt_runtime_string = fmt::runtime_format_string<Char>;
+#else
+using fmt_runtime_string = fmt::basic_runtime<Char>;
+#endif
+
 // clang doesn't like SFINAE disabled constructor in std::is_convertible<> so have to repeat the condition from basic_format_string here,
 // in addition, fmt::basic_runtime<Char> is only convertible to basic_format_string<Char> but not basic_string_view<Char>
 template<class T, class Char = char>
 struct is_convertible_to_basic_format_string
     : std::integral_constant<bool,
-          std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value>
+          std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt_runtime_string<Char>>::value>
 {};
 
 #    if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)