66#include < spdlog/details/null_mutex.h>
77#include < spdlog/tweakme.h>
88
9+ #include < array>
910#include < atomic>
1011#include < chrono>
1112#include < cstdio>
9394#define SPDLOG_DEPRECATED
9495#endif
9596
97+ #if __cplusplus >= 201703L
98+ #define SPDLOG_NODISCARD [[nodiscard]]
99+ #else
100+ #define SPDLOG_NODISCARD
101+ #endif
102+
96103// disable thread local on msvc 2013
97104#ifndef SPDLOG_NO_TLS
98105#if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__cplusplus_winrt)
101108#endif
102109
103110#ifndef SPDLOG_FUNCTION
104- #define SPDLOG_FUNCTION static_cast <const char *>(__FUNCTION__)
111+ #define SPDLOG_FUNCTION static_cast <const char *>(__FUNCTION__)
105112#endif
106113
107114#ifdef SPDLOG_NO_EXCEPTIONS
115122#else
116123#define SPDLOG_TRY try
117124#define SPDLOG_THROW (ex ) throw (ex)
118- #define SPDLOG_CATCH_STD \
119- catch (const std::exception &) { \
125+ #define SPDLOG_CATCH_STD \
126+ catch (const std::exception&) { \
120127 }
121128#endif
122129
@@ -141,7 +148,7 @@ using filename_t = std::string;
141148using log_clock = std::chrono::system_clock;
142149using sink_ptr = std::shared_ptr<sinks::sink>;
143150using sinks_init_list = std::initializer_list<sink_ptr>;
144- using err_handler = std::function<void (const std::string & err_msg)>;
151+ using err_handler = std::function<void (const std::string& err_msg)>;
145152#ifdef SPDLOG_USE_STD_FORMAT
146153namespace fmt_lib = std;
147154
@@ -253,32 +260,61 @@ enum level_enum : int {
253260 n_levels
254261};
255262
256- #define SPDLOG_LEVEL_NAME_TRACE spdlog::string_view_t (" trace" , 5 )
257- #define SPDLOG_LEVEL_NAME_DEBUG spdlog::string_view_t (" debug" , 5 )
258- #define SPDLOG_LEVEL_NAME_INFO spdlog::string_view_t (" info" , 4 )
259- #define SPDLOG_LEVEL_NAME_WARNING spdlog::string_view_t (" warning" , 7 )
260- #define SPDLOG_LEVEL_NAME_ERROR spdlog::string_view_t (" error" , 5 )
261- #define SPDLOG_LEVEL_NAME_CRITICAL spdlog::string_view_t (" critical" , 8 )
262- #define SPDLOG_LEVEL_NAME_OFF spdlog::string_view_t (" off" , 3 )
263+ #if __cplusplus >= 201703L
264+ SPDLOG_INLINE SPDLOG_CONSTEXPR spdlog::string_view_t SPDLOG_LEVEL_NAME_TRACE{" trace" , 5 };
265+ SPDLOG_INLINE SPDLOG_CONSTEXPR spdlog::string_view_t SPDLOG_LEVEL_NAME_DEBUG{" debug" , 5 };
266+ SPDLOG_INLINE SPDLOG_CONSTEXPR spdlog::string_view_t SPDLOG_LEVEL_NAME_INFO{" info" , 4 };
267+ SPDLOG_INLINE SPDLOG_CONSTEXPR spdlog::string_view_t SPDLOG_LEVEL_NAME_WARNING{" warning" , 7 };
268+ SPDLOG_INLINE SPDLOG_CONSTEXPR spdlog::string_view_t SPDLOG_LEVEL_NAME_ERROR{" error" , 5 };
269+ SPDLOG_INLINE SPDLOG_CONSTEXPR spdlog::string_view_t SPDLOG_LEVEL_NAME_CRITICAL{" critical" , 8 };
270+ SPDLOG_INLINE SPDLOG_CONSTEXPR spdlog::string_view_t SPDLOG_LEVEL_NAME_OFF{" off" , 3 };
271+ #else
272+ SPDLOG_CONSTEXPR spdlog::string_view_t SPDLOG_LEVEL_NAME_TRACE{" trace" , 5 };
273+ SPDLOG_CONSTEXPR spdlog::string_view_t SPDLOG_LEVEL_NAME_DEBUG{" debug" , 5 };
274+ SPDLOG_CONSTEXPR spdlog::string_view_t SPDLOG_LEVEL_NAME_INFO{" info" , 4 };
275+ SPDLOG_CONSTEXPR spdlog::string_view_t SPDLOG_LEVEL_NAME_WARNING{" warning" , 7 };
276+ SPDLOG_CONSTEXPR spdlog::string_view_t SPDLOG_LEVEL_NAME_ERROR{" error" , 5 };
277+ SPDLOG_CONSTEXPR spdlog::string_view_t SPDLOG_LEVEL_NAME_CRITICAL{" critical" , 8 };
278+ SPDLOG_CONSTEXPR spdlog::string_view_t SPDLOG_LEVEL_NAME_OFF{" off" , 3 };
279+ #endif
263280
264281#if !defined(SPDLOG_LEVEL_NAMES)
265- #define SPDLOG_LEVEL_NAMES \
266- { \
267- SPDLOG_LEVEL_NAME_TRACE, SPDLOG_LEVEL_NAME_DEBUG, SPDLOG_LEVEL_NAME_INFO, \
268- SPDLOG_LEVEL_NAME_WARNING, SPDLOG_LEVEL_NAME_ERROR, SPDLOG_LEVEL_NAME_CRITICAL, \
269- SPDLOG_LEVEL_NAME_OFF \
270- }
282+ using level_names_t = std::array<spdlog::string_view_t , n_levels>;
283+
284+ using level_names_value_t = level_names_t ::value_type;
285+
286+ #if __cplusplus >= 201703L
287+ SPDLOG_INLINE
288+ #endif
289+ SPDLOG_CONSTEXPR level_names_t SPDLOG_LEVEL_NAMES{
290+ SPDLOG_LEVEL_NAME_TRACE, SPDLOG_LEVEL_NAME_DEBUG, SPDLOG_LEVEL_NAME_INFO,
291+ SPDLOG_LEVEL_NAME_WARNING, SPDLOG_LEVEL_NAME_ERROR, SPDLOG_LEVEL_NAME_CRITICAL,
292+ SPDLOG_LEVEL_NAME_OFF};
271293#endif
272294
273295#if !defined(SPDLOG_SHORT_LEVEL_NAMES)
296+ using short_level_names_t = std::array<const char *, n_levels>;
297+
298+ using level_short_names_value_t = short_level_names_t ::value_type;
299+
300+ #if __cplusplus >= 201703L
301+ SPDLOG_INLINE
302+ #endif
303+ SPDLOG_CONSTEXPR short_level_names_t SPDLOG_SHORT_LEVEL_NAMES{" T" , " D" , " I" , " W" , " E" , " C" , " O" };
274304
275- #define SPDLOG_SHORT_LEVEL_NAMES \
276- { " T" , " D" , " I" , " W" , " E" , " C" , " O" }
277305#endif
278306
279- SPDLOG_API const string_view_t &to_string_view (spdlog::level::level_enum l) SPDLOG_NOEXCEPT;
280- SPDLOG_API const char *to_short_c_str (spdlog::level::level_enum l) SPDLOG_NOEXCEPT;
281- SPDLOG_API spdlog::level::level_enum from_str (const std::string &name) SPDLOG_NOEXCEPT;
307+ SPDLOG_API SPDLOG_NODISCARD SPDLOG_INLINE SPDLOG_CONSTEXPR const level_names_value_t & to_string_view (
308+ spdlog::level::level_enum l) SPDLOG_NOEXCEPT {
309+ return SPDLOG_LEVEL_NAMES[l];
310+ }
311+
312+ SPDLOG_API SPDLOG_NODISCARD SPDLOG_INLINE SPDLOG_CONSTEXPR level_short_names_value_t
313+ to_short_c_str (spdlog::level::level_enum l) SPDLOG_NOEXCEPT {
314+ return SPDLOG_SHORT_LEVEL_NAMES[l];
315+ }
316+
317+ SPDLOG_API spdlog::level::level_enum from_str (const std::string& name) SPDLOG_NOEXCEPT;
282318
283319} // namespace level
284320
@@ -302,47 +338,41 @@ enum class pattern_time_type {
302338class SPDLOG_API spdlog_ex : public std::exception {
303339public:
304340 explicit spdlog_ex (std::string msg);
305- spdlog_ex (const std::string & msg, int last_errno);
306- const char * what () const SPDLOG_NOEXCEPT override ;
341+ spdlog_ex (const std::string& msg, int last_errno);
342+ const char * what () const SPDLOG_NOEXCEPT override ;
307343
308344private:
309345 std::string msg_;
310346};
311347
312- [[noreturn]] SPDLOG_API void throw_spdlog_ex (const std::string & msg, int last_errno);
348+ [[noreturn]] SPDLOG_API void throw_spdlog_ex (const std::string& msg, int last_errno);
313349[[noreturn]] SPDLOG_API void throw_spdlog_ex (std::string msg);
314350
315351struct source_loc {
316352 SPDLOG_CONSTEXPR source_loc () = default;
317- SPDLOG_CONSTEXPR source_loc (const char * filename_in, int line_in, const char * funcname_in)
353+ SPDLOG_CONSTEXPR source_loc (const char * filename_in, int line_in, const char * funcname_in)
318354 : filename{filename_in},
319355 line{line_in},
320356 funcname{funcname_in} {}
321357
322358 SPDLOG_CONSTEXPR bool empty () const SPDLOG_NOEXCEPT { return line <= 0 ; }
323- const char * filename{nullptr };
359+ const char * filename{nullptr };
324360 int line{0 };
325- const char * funcname{nullptr };
361+ const char * funcname{nullptr };
326362};
327363
328364struct file_event_handlers {
329- file_event_handlers ()
330- : before_open(nullptr ),
331- after_open (nullptr ),
332- before_close(nullptr ),
333- after_close(nullptr ) {}
334-
335- std::function<void (const filename_t &filename)> before_open;
336- std::function<void (const filename_t &filename, std::FILE *file_stream)> after_open;
337- std::function<void (const filename_t &filename, std::FILE *file_stream)> before_close;
338- std::function<void (const filename_t &filename)> after_close;
365+ std::function<void (const filename_t & filename)> before_open{nullptr };
366+ std::function<void (const filename_t & filename, std::FILE* file_stream)> after_open{nullptr };
367+ std::function<void (const filename_t & filename, std::FILE* file_stream)> before_close{nullptr };
368+ std::function<void (const filename_t & filename)> after_close{nullptr };
339369};
340370
341371namespace details {
342372
343373// to_string_view
344374
345- SPDLOG_CONSTEXPR_FUNC spdlog::string_view_t to_string_view (const memory_buf_t & buf)
375+ SPDLOG_CONSTEXPR_FUNC spdlog::string_view_t to_string_view (const memory_buf_t & buf)
346376 SPDLOG_NOEXCEPT {
347377 return spdlog::string_view_t {buf.data (), buf.size ()};
348378}
@@ -353,7 +383,7 @@ SPDLOG_CONSTEXPR_FUNC spdlog::string_view_t to_string_view(spdlog::string_view_t
353383}
354384
355385#if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
356- SPDLOG_CONSTEXPR_FUNC spdlog::wstring_view_t to_string_view (const wmemory_buf_t & buf)
386+ SPDLOG_CONSTEXPR_FUNC spdlog::wstring_view_t to_string_view (const wmemory_buf_t & buf)
357387 SPDLOG_NOEXCEPT {
358388 return spdlog::wstring_view_t {buf.data (), buf.size ()};
359389}
@@ -381,7 +411,7 @@ template <bool B, class T = void>
381411using enable_if_t = typename std::enable_if<B, T>::type;
382412
383413template <typename T, typename ... Args>
384- std::unique_ptr<T> make_unique (Args &&...args) {
414+ std::unique_ptr<T> make_unique (Args&&... args) {
385415 static_assert (!std::is_array<T>::value, " arrays not supported" );
386416 return std::unique_ptr<T>(new T (std::forward<Args>(args)...));
387417}
0 commit comments