diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e2bfc7d..b249f42a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,12 @@ target_include_directories(spdlog PUBLIC "$" "$") target_link_libraries(spdlog PUBLIC Threads::Threads) +set_target_properties(spdlog PROPERTIES DEFINE_SYMBOL SPDLOG_EXPORTS) + +if (BUILD_SHARED_LIBS) + target_compile_definitions(spdlog PUBLIC SPDLOG_SHARED) +endif () + spdlog_enable_warnings(spdlog) #--------------------------------------------------------------------------------------- @@ -93,7 +99,6 @@ target_include_directories(spdlog_header_only INTERFACE "$") target_link_libraries(spdlog_header_only INTERFACE Threads::Threads) - #--------------------------------------------------------------------------------------- # Use fmt package if using exertnal fmt #--------------------------------------------------------------------------------------- diff --git a/include/spdlog/async.h b/include/spdlog/async.h index bf8187db..e3c845e1 100644 --- a/include/spdlog/async.h +++ b/include/spdlog/async.h @@ -14,6 +14,7 @@ // This is because each message in the queue holds a shared_ptr to the // originating logger. +#include "spdlog/common.h" #include "spdlog/async_logger.h" #include "spdlog/details/registry.h" #include "spdlog/details/thread_pool.h" @@ -25,14 +26,14 @@ namespace spdlog { namespace details { -static const size_t default_async_q_size = 8192; +SPDLOG_CONSTEXPR static const size_t default_async_q_size = 8192; } // async logger factory - creates async loggers backed with thread pool. // if a global thread pool doesn't already exist, create it with default queue // size of 8192 items and single thread. template -struct async_factory_impl +struct SPDLOG_API async_factory_impl { template static std::shared_ptr create(std::string logger_name, SinkArgs &&... args) diff --git a/include/spdlog/async_logger.h b/include/spdlog/async_logger.h index 9899837b..e05e12ea 100644 --- a/include/spdlog/async_logger.h +++ b/include/spdlog/async_logger.h @@ -14,6 +14,7 @@ // Upon destruction, logs all remaining messages in the queue before // destructing.. +#include "spdlog/common.h" #include "spdlog/logger.h" namespace spdlog { @@ -30,7 +31,7 @@ namespace details { class thread_pool; } -class async_logger final : public std::enable_shared_from_this, public logger +class SPDLOG_API async_logger final : public std::enable_shared_from_this, public logger { friend class details::thread_pool; diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 49625c0b..94f29855 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -34,6 +34,26 @@ #define SPDLOG_INLINE inline #endif +#if !defined(SPDLOG_HEADER_ONLY) +# if defined(_WIN32) || defined(__CYGWIN__) +# if defined(SPDLOG_EXPORTS) +# define SPDLOG_API __declspec(dllexport) +# elif defined(SPDLOG_SHARED) +# define SPDLOG_API __declspec(dllimport) +# endif +# elif __GNUC__ >= 4 +# define SPDLOG_API __attribute__ ((visibility ("default"))) +# define SPDLOG_PRIVATE __attribute__ ((visibility ("hidden"))) +# endif +#endif + +#ifndef SPDLOG_API +# define SPDLOG_API +#endif +#ifndef SPDLOG_PRIVATE +# define SPDLOG_PRIVATE +#endif + #include "spdlog/fmt/fmt.h" // visual studio upto 2013 does not support noexcept nor constexpr @@ -144,9 +164,9 @@ enum level_enum } #endif -string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT; -const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT; -spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT; +SPDLOG_API string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT; +SPDLOG_API const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT; +SPDLOG_API spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT; using level_hasher = std::hash; } // namespace level @@ -174,7 +194,7 @@ enum class pattern_time_type // // Log exception // -class spdlog_ex : public std::exception +class SPDLOG_API spdlog_ex : public std::exception { public: explicit spdlog_ex(std::string msg); @@ -185,7 +205,7 @@ private: std::string msg_; }; -struct source_loc +struct SPDLOG_API source_loc { SPDLOG_CONSTEXPR source_loc() = default; SPDLOG_CONSTEXPR source_loc(const char *filename_in, int line_in, const char *funcname_in) diff --git a/include/spdlog/details/circular_q.h b/include/spdlog/details/circular_q.h index 4db554c0..15c46959 100644 --- a/include/spdlog/details/circular_q.h +++ b/include/spdlog/details/circular_q.h @@ -5,11 +5,12 @@ #pragma once #include +#include "spdlog/common.h" namespace spdlog { namespace details { template -class circular_q +class SPDLOG_API circular_q { public: using item_type = T; diff --git a/include/spdlog/details/console_globals.h b/include/spdlog/details/console_globals.h index 098f1fab..6f598f5d 100644 --- a/include/spdlog/details/console_globals.h +++ b/include/spdlog/details/console_globals.h @@ -3,19 +3,20 @@ #pragma once +#include "spdlog/common.h" #include "spdlog/details/null_mutex.h" #include namespace spdlog { namespace details { -struct console_mutex +struct SPDLOG_API console_mutex { using mutex_t = std::mutex; static mutex_t &mutex(); }; -struct console_nullmutex +struct SPDLOG_API console_nullmutex { using mutex_t = null_mutex; static mutex_t &mutex(); diff --git a/include/spdlog/details/file_helper.h b/include/spdlog/details/file_helper.h index 6fdecd06..d0b70caf 100644 --- a/include/spdlog/details/file_helper.h +++ b/include/spdlog/details/file_helper.h @@ -13,7 +13,7 @@ namespace details { // When failing to open a file, retry several times(5) with a delay interval(10 ms). // Throw spdlog_ex exception on errors. -class file_helper +class SPDLOG_API file_helper { public: explicit file_helper() = default; diff --git a/include/spdlog/details/fmt_helper.h b/include/spdlog/details/fmt_helper.h index 67494ed5..02217d9f 100644 --- a/include/spdlog/details/fmt_helper.h +++ b/include/spdlog/details/fmt_helper.h @@ -4,8 +4,8 @@ #include #include -#include "spdlog/fmt/fmt.h" #include "spdlog/common.h" +#include "spdlog/fmt/fmt.h" // Some fmt helpers to efficiently format and pad ints and strings namespace spdlog { diff --git a/include/spdlog/details/log_msg.h b/include/spdlog/details/log_msg.h index f2976df8..bcbcf8dd 100644 --- a/include/spdlog/details/log_msg.h +++ b/include/spdlog/details/log_msg.h @@ -8,7 +8,7 @@ namespace spdlog { namespace details { -struct log_msg +struct SPDLOG_API log_msg { log_msg(source_loc loc, string_view_t logger_name, level::level_enum lvl, string_view_t msg); log_msg(string_view_t logger_name, level::level_enum lvl, string_view_t msg); diff --git a/include/spdlog/details/mpmc_blocking_q.h b/include/spdlog/details/mpmc_blocking_q.h index d8a1efe2..83c82438 100644 --- a/include/spdlog/details/mpmc_blocking_q.h +++ b/include/spdlog/details/mpmc_blocking_q.h @@ -10,6 +10,7 @@ // dequeue_for(..) - will block until the queue is not empty or timeout have // passed. +#include "spdlog/common.h" #include "spdlog/details/circular_q.h" #include @@ -19,7 +20,7 @@ namespace spdlog { namespace details { template -class mpmc_blocking_queue +class SPDLOG_API mpmc_blocking_queue { public: using item_type = T; diff --git a/include/spdlog/details/null_mutex.h b/include/spdlog/details/null_mutex.h index d1062db7..dc30c376 100644 --- a/include/spdlog/details/null_mutex.h +++ b/include/spdlog/details/null_mutex.h @@ -4,11 +4,12 @@ #pragma once #include +#include "spdlog/common.h" // null, no cost dummy "mutex" and dummy "atomic" int namespace spdlog { namespace details { -struct null_mutex +struct SPDLOG_API null_mutex { void lock() {} void unlock() {} diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 27694494..00fd0992 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -10,15 +10,15 @@ namespace spdlog { namespace details { namespace os { -spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT; +SPDLOG_API spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT; -std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT; +SPDLOG_API std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT; -std::tm localtime() SPDLOG_NOEXCEPT; +SPDLOG_API std::tm localtime() SPDLOG_NOEXCEPT; -std::tm gmtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT; +SPDLOG_API std::tm gmtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT; -std::tm gmtime() SPDLOG_NOEXCEPT; +SPDLOG_API std::tm gmtime() SPDLOG_NOEXCEPT; // eol definition #if !defined(SPDLOG_EOL) @@ -38,50 +38,50 @@ const char folder_sep = '\\'; SPDLOG_CONSTEXPR static const char folder_sep = '/'; #endif -void prevent_child_fd(FILE *f); +SPDLOG_API void prevent_child_fd(FILE *f); // fopen_s on non windows for writing -bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode); +SPDLOG_API bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode); -int remove(const filename_t &filename) SPDLOG_NOEXCEPT; +SPDLOG_API int remove(const filename_t &filename) SPDLOG_NOEXCEPT; -int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT; +SPDLOG_API int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT; // Return if file exists -bool file_exists(const filename_t &filename) SPDLOG_NOEXCEPT; +SPDLOG_API bool file_exists(const filename_t &filename) SPDLOG_NOEXCEPT; // Return file size according to open FILE* object -size_t filesize(FILE *f); +SPDLOG_API size_t filesize(FILE *f); // Return utc offset in minutes or throw spdlog_ex on failure -int utc_minutes_offset(const std::tm &tm = details::os::localtime()); +SPDLOG_API int utc_minutes_offset(const std::tm &tm = details::os::localtime()); // Return current thread id as size_t // It exists because the std::this_thread::get_id() is much slower(especially // under VS 2013) -size_t _thread_id() SPDLOG_NOEXCEPT; +SPDLOG_API size_t _thread_id() SPDLOG_NOEXCEPT; // Return current thread id as size_t (from thread local storage) -size_t thread_id() SPDLOG_NOEXCEPT; +SPDLOG_API size_t thread_id() SPDLOG_NOEXCEPT; // This is avoid msvc issue in sleep_for that happens if the clock changes. // See https://github.com/gabime/spdlog/issues/609 -void sleep_for_millis(int milliseconds) SPDLOG_NOEXCEPT; +SPDLOG_API void sleep_for_millis(int milliseconds) SPDLOG_NOEXCEPT; -std::string filename_to_str(const filename_t &filename); +SPDLOG_API std::string filename_to_str(const filename_t &filename); -int pid() SPDLOG_NOEXCEPT; +SPDLOG_API int pid() SPDLOG_NOEXCEPT; // Determine if the terminal supports colors // Source: https://github.com/agauniyal/rang/ -bool is_color_terminal() SPDLOG_NOEXCEPT; +SPDLOG_API bool is_color_terminal() SPDLOG_NOEXCEPT; // Detrmine if the terminal attached // Source: https://github.com/agauniyal/rang/ -bool in_terminal(FILE *file) SPDLOG_NOEXCEPT; +SPDLOG_API bool in_terminal(FILE *file) SPDLOG_NOEXCEPT; #if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32) -void wstr_to_utf8buf(basic_string_view_t wstr, fmt::memory_buffer &target); +SPDLOG_API void wstr_to_utf8buf(basic_string_view_t wstr, fmt::memory_buffer &target); #endif } // namespace os diff --git a/include/spdlog/details/pattern_formatter-inl.h b/include/spdlog/details/pattern_formatter-inl.h index 90271b97..4d4679c2 100644 --- a/include/spdlog/details/pattern_formatter-inl.h +++ b/include/spdlog/details/pattern_formatter-inl.h @@ -865,7 +865,6 @@ public: // print elapsed time since last message template - class elapsed_formatter final : public flag_formatter { public: diff --git a/include/spdlog/details/pattern_formatter.h b/include/spdlog/details/pattern_formatter.h index 1fcaf394..e919cf6c 100644 --- a/include/spdlog/details/pattern_formatter.h +++ b/include/spdlog/details/pattern_formatter.h @@ -19,7 +19,7 @@ namespace spdlog { namespace details { // padding information. -struct padding_info +struct SPDLOG_API padding_info { enum pad_side { @@ -42,7 +42,7 @@ struct padding_info const pad_side side_ = left; }; -class flag_formatter +class SPDLOG_API flag_formatter { public: explicit flag_formatter(padding_info padinfo) @@ -58,7 +58,7 @@ protected: } // namespace details -class pattern_formatter final : public formatter +class SPDLOG_API pattern_formatter final : public formatter { public: explicit pattern_formatter( @@ -81,16 +81,16 @@ private: std::chrono::seconds last_log_secs_; std::vector> formatters_; - std::tm get_time_(const details::log_msg &msg); + SPDLOG_PRIVATE std::tm get_time_(const details::log_msg &msg); template - void handle_flag_(char flag, details::padding_info padding); + SPDLOG_PRIVATE void handle_flag_(char flag, details::padding_info padding); // Extract given pad spec (e.g. %8X) // Advance the given it pass the end of the padding spec found (if any) // Return padding. - details::padding_info handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end); + SPDLOG_PRIVATE details::padding_info handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end); - void compile_pattern_(const std::string &pattern); + SPDLOG_PRIVATE void compile_pattern_(const std::string &pattern); }; } // namespace spdlog diff --git a/include/spdlog/details/periodic_worker.h b/include/spdlog/details/periodic_worker.h index d3b5c639..d7265833 100644 --- a/include/spdlog/details/periodic_worker.h +++ b/include/spdlog/details/periodic_worker.h @@ -14,10 +14,11 @@ #include #include #include +#include "spdlog/common.h" namespace spdlog { namespace details { -class periodic_worker +class SPDLOG_API periodic_worker { public: periodic_worker(const std::function &callback_fun, std::chrono::seconds interval); diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h index f96a7698..c9e89e49 100644 --- a/include/spdlog/details/registry.h +++ b/include/spdlog/details/registry.h @@ -24,7 +24,7 @@ namespace details { class thread_pool; class periodic_worker; -class registry +class SPDLOG_API registry { public: registry(const registry &) = delete; @@ -78,11 +78,12 @@ public: static registry &instance(); private: - registry(); - ~registry() = default; + SPDLOG_PRIVATE registry(); + SPDLOG_PRIVATE ~registry() = default; + + SPDLOG_PRIVATE void throw_if_exists_(const std::string &logger_name); + SPDLOG_PRIVATE void register_logger_(std::shared_ptr new_logger); - void throw_if_exists_(const std::string &logger_name); - void register_logger_(std::shared_ptr new_logger); std::mutex logger_map_mutex_, flusher_mutex_; std::recursive_mutex tp_mutex_; std::unordered_map> loggers_; diff --git a/include/spdlog/details/synchronous_factory.h b/include/spdlog/details/synchronous_factory.h index 68f5c214..ba7f01ae 100644 --- a/include/spdlog/details/synchronous_factory.h +++ b/include/spdlog/details/synchronous_factory.h @@ -3,6 +3,7 @@ #pragma once +#include "spdlog/common.h" #include "registry.h" namespace spdlog { @@ -10,7 +11,7 @@ namespace spdlog { // Default logger factory- creates synchronous loggers class logger; -struct synchronous_factory +struct SPDLOG_API synchronous_factory { template static std::shared_ptr create(std::string logger_name, SinkArgs &&... args) @@ -21,4 +22,4 @@ struct synchronous_factory return new_logger; } }; -} // namespace spdlog \ No newline at end of file +} // namespace spdlog diff --git a/include/spdlog/details/thread_pool.h b/include/spdlog/details/thread_pool.h index f7904cf1..3637ef3b 100644 --- a/include/spdlog/details/thread_pool.h +++ b/include/spdlog/details/thread_pool.h @@ -3,6 +3,7 @@ #pragma once +#include "spdlog/common.h" #include "spdlog/details/log_msg.h" #include "spdlog/details/mpmc_blocking_q.h" #include "spdlog/details/os.h" @@ -29,7 +30,7 @@ enum class async_msg_type // Async msg to move to/from the queue // Movable only. should never be copied -struct async_msg +struct SPDLOG_API async_msg { async_msg_type msg_type; level::level_enum level; @@ -113,7 +114,7 @@ struct async_msg } }; -class thread_pool +class SPDLOG_API thread_pool { public: using item_type = async_msg; @@ -137,13 +138,13 @@ private: std::vector threads_; - void post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy); - void worker_loop_(); + SPDLOG_PRIVATE void post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy); + SPDLOG_PRIVATE void worker_loop_(); // process next message in the queue // return true if this thread should still be active (while no terminate msg // was received) - bool process_next_msg_(); + SPDLOG_PRIVATE bool process_next_msg_(); }; } // namespace details @@ -151,4 +152,4 @@ private: #ifdef SPDLOG_HEADER_ONLY #include "thread_pool-inl.h" -#endif \ No newline at end of file +#endif diff --git a/include/spdlog/fmt/fmt.h b/include/spdlog/fmt/fmt.h index 5d039b8c..a438022c 100644 --- a/include/spdlog/fmt/fmt.h +++ b/include/spdlog/fmt/fmt.h @@ -11,17 +11,19 @@ // #if !defined(SPDLOG_FMT_EXTERNAL) -#ifdef SPDLOG_HEADER_ONLY -#ifndef FMT_HEADER_ONLY -#define FMT_HEADER_ONLY -#endif -#endif -#ifndef FMT_USE_WINDOWS_H -#define FMT_USE_WINDOWS_H 0 -#endif -#include "bundled/core.h" -#include "bundled/format.h" +# include "spdlog/common.h" +# if defined(SPDLOG_HEADER_ONLY) && !defined(FMT_HEADER_ONLY) +# define FMT_HEADER_ONLY +# endif +# if defined(SDPLOG_SHARED) && !defined(FMT_SHARED) +# define FMT_SHARED +# endif +# ifndef FMT_USE_WINDOWS_H +# define FMT_USE_WINDOWS_H 0 +# endif +# include "bundled/core.h" +# include "bundled/format.h" #else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib -#include "fmt/core.h" -#include "fmt/format.h" +# include "fmt/core.h" +# include "fmt/format.h" #endif diff --git a/include/spdlog/fmt/ostr.h b/include/spdlog/fmt/ostr.h index 9902898f..80548898 100644 --- a/include/spdlog/fmt/ostr.h +++ b/include/spdlog/fmt/ostr.h @@ -8,11 +8,9 @@ // include bundled or external copy of fmtlib's ostream support // #if !defined(SPDLOG_FMT_EXTERNAL) -#ifndef FMT_HEADER_ONLY -#define FMT_HEADER_ONLY -#endif -#include "bundled/ostream.h" +#include "spdlog/common.h" #include "fmt.h" +#include "bundled/ostream.h" #else #include #endif diff --git a/include/spdlog/formatter.h b/include/spdlog/formatter.h index b133f6e9..b2e88c86 100644 --- a/include/spdlog/formatter.h +++ b/include/spdlog/formatter.h @@ -3,12 +3,13 @@ #pragma once +#include "spdlog/common.h" #include "fmt/fmt.h" #include "spdlog/details/log_msg.h" namespace spdlog { -class formatter +class SPDLOG_API formatter { public: virtual ~formatter() = default; diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 8d991e58..64e9a6bf 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -35,7 +35,7 @@ } namespace spdlog { -class logger +class SPDLOG_API logger { public: // Empty logger @@ -328,7 +328,7 @@ protected: void err_handler_(const std::string &msg); }; -void swap(logger &a, logger &b); +SPDLOG_API void swap(logger &a, logger &b); } // namespace spdlog diff --git a/include/spdlog/sinks/android_sink.h b/include/spdlog/sinks/android_sink.h index f1f2e0e6..0c40da79 100644 --- a/include/spdlog/sinks/android_sink.h +++ b/include/spdlog/sinks/android_sink.h @@ -5,6 +5,7 @@ #ifdef __ANDROID__ +#include "spdlog/common.h" #include "spdlog/details/fmt_helper.h" #include "spdlog/details/null_mutex.h" #include "spdlog/details/os.h" @@ -28,7 +29,7 @@ namespace sinks { * Android sink (logging using __android_log_write) */ template -class android_sink final : public base_sink +class SPDLOG_API android_sink final : public base_sink { public: explicit android_sink(std::string tag = "spdlog", bool use_raw_msg = false) @@ -116,4 +117,4 @@ inline std::shared_ptr android_logger_st(const std::string &logger_name, } // namespace spdlog -#endif // __ANDROID__ \ No newline at end of file +#endif // __ANDROID__ diff --git a/include/spdlog/sinks/ansicolor_sink.h b/include/spdlog/sinks/ansicolor_sink.h index f383b5a5..3038c512 100644 --- a/include/spdlog/sinks/ansicolor_sink.h +++ b/include/spdlog/sinks/ansicolor_sink.h @@ -3,6 +3,7 @@ #pragma once +#include "spdlog/common.h" #include "spdlog/details/console_globals.h" #include "spdlog/details/null_mutex.h" #include "spdlog/sinks/sink.h" @@ -22,7 +23,7 @@ namespace sinks { */ template -class ansicolor_sink : public sink +class SPDLOG_API ansicolor_sink : public sink { public: using mutex_t = typename ConsoleMutex::mutex_t; @@ -81,19 +82,19 @@ private: bool should_do_colors_; std::unique_ptr formatter_; std::unordered_map colors_; - void print_ccode_(const string_view_t &color_code); - void print_range_(const fmt::memory_buffer &formatted, size_t start, size_t end); + SPDLOG_PRIVATE void print_ccode_(const string_view_t &color_code); + SPDLOG_PRIVATE void print_range_(const fmt::memory_buffer &formatted, size_t start, size_t end); }; template -class ansicolor_stdout_sink : public ansicolor_sink +class SPDLOG_API ansicolor_stdout_sink : public ansicolor_sink { public: explicit ansicolor_stdout_sink(color_mode mode = color_mode::automatic); }; template -class ansicolor_stderr_sink : public ansicolor_sink +class SPDLOG_API ansicolor_stderr_sink : public ansicolor_sink { public: explicit ansicolor_stderr_sink(color_mode mode = color_mode::automatic); diff --git a/include/spdlog/sinks/base_sink.h b/include/spdlog/sinks/base_sink.h index be3956a7..4a357927 100644 --- a/include/spdlog/sinks/base_sink.h +++ b/include/spdlog/sinks/base_sink.h @@ -16,7 +16,7 @@ namespace spdlog { namespace sinks { template -class base_sink : public sink +class SPDLOG_API base_sink : public sink { public: base_sink(); diff --git a/include/spdlog/sinks/basic_file_sink.h b/include/spdlog/sinks/basic_file_sink.h index 899b89fa..b2cb0d1b 100644 --- a/include/spdlog/sinks/basic_file_sink.h +++ b/include/spdlog/sinks/basic_file_sink.h @@ -3,6 +3,7 @@ #pragma once +#include "spdlog/common.h" #include "spdlog/details/file_helper.h" #include "spdlog/details/null_mutex.h" #include "spdlog/sinks/base_sink.h" @@ -17,7 +18,7 @@ namespace sinks { * Trivial file sink with single file as target */ template -class basic_file_sink final : public base_sink +class SPDLOG_API basic_file_sink final : public base_sink { public: explicit basic_file_sink(const filename_t &filename, bool truncate = false); @@ -55,4 +56,4 @@ inline std::shared_ptr basic_logger_st(const std::string &logger_name, c #ifdef SPDLOG_HEADER_ONLY #include "basic_file_sink-inl.h" -#endif \ No newline at end of file +#endif diff --git a/include/spdlog/sinks/daily_file_sink.h b/include/spdlog/sinks/daily_file_sink.h index a0798bee..047e3ade 100644 --- a/include/spdlog/sinks/daily_file_sink.h +++ b/include/spdlog/sinks/daily_file_sink.h @@ -3,6 +3,7 @@ #pragma once +#include "spdlog/common.h" #include "spdlog/details/file_helper.h" #include "spdlog/details/null_mutex.h" #include "spdlog/fmt/fmt.h" @@ -22,7 +23,7 @@ namespace sinks { /* * Generator of daily log file names in format basename.YYYY-MM-DD.ext */ -struct daily_filename_calculator +struct SPDLOG_API daily_filename_calculator { // Create filename for the form basename.YYYY-MM-DD static filename_t calc_filename(const filename_t &filename, const tm &now_tm) @@ -40,7 +41,7 @@ struct daily_filename_calculator * Rotating file sink based on date. rotates at midnight */ template -class daily_file_sink final : public base_sink +class SPDLOG_API daily_file_sink final : public base_sink { public: // create daily file sink which rotates on given time diff --git a/include/spdlog/sinks/dist_sink.h b/include/spdlog/sinks/dist_sink.h index c7f207d7..a588d911 100644 --- a/include/spdlog/sinks/dist_sink.h +++ b/include/spdlog/sinks/dist_sink.h @@ -3,6 +3,7 @@ #pragma once +#include "spdlog/common.h" #include "base_sink.h" #include "spdlog/details/log_msg.h" #include "spdlog/details/null_mutex.h" @@ -20,7 +21,7 @@ namespace spdlog { namespace sinks { template -class dist_sink : public base_sink +class SPDLOG_API dist_sink : public base_sink { public: dist_sink() = default; diff --git a/include/spdlog/sinks/dup_filter_sink.h b/include/spdlog/sinks/dup_filter_sink.h index 66c59359..db700a14 100644 --- a/include/spdlog/sinks/dup_filter_sink.h +++ b/include/spdlog/sinks/dup_filter_sink.h @@ -3,6 +3,7 @@ #pragma once +#include "spdlog/common.h" #include "dist_sink.h" #include "spdlog/details/null_mutex.h" #include "spdlog/details/log_msg.h" @@ -40,7 +41,7 @@ namespace spdlog { namespace sinks { template -class dup_filter_sink : public dist_sink +class SPDLOG_API dup_filter_sink : public dist_sink { public: template diff --git a/include/spdlog/sinks/msvc_sink.h b/include/spdlog/sinks/msvc_sink.h index 08e029a0..e1c19e6f 100644 --- a/include/spdlog/sinks/msvc_sink.h +++ b/include/spdlog/sinks/msvc_sink.h @@ -5,6 +5,7 @@ #if defined(_WIN32) +#include "spdlog/common.h" #include "spdlog/details/null_mutex.h" #include "spdlog/sinks/base_sink.h" @@ -19,7 +20,7 @@ namespace sinks { * MSVC sink (logging using OutputDebugStringA) */ template -class msvc_sink : public base_sink +class SPDLOG_API msvc_sink : public base_sink { public: explicit msvc_sink() {} diff --git a/include/spdlog/sinks/null_sink.h b/include/spdlog/sinks/null_sink.h index 44a45a3e..bcd07115 100644 --- a/include/spdlog/sinks/null_sink.h +++ b/include/spdlog/sinks/null_sink.h @@ -3,6 +3,7 @@ #pragma once +#include "spdlog/common.h" #include "spdlog/details/null_mutex.h" #include "spdlog/sinks/base_sink.h" #include "spdlog/details/synchronous_factory.h" @@ -13,7 +14,7 @@ namespace spdlog { namespace sinks { template -class null_sink : public base_sink +class SPDLOG_API null_sink : public base_sink { protected: void sink_it_(const details::log_msg &) override {} diff --git a/include/spdlog/sinks/ostream_sink.h b/include/spdlog/sinks/ostream_sink.h index 6a728a3a..9c456a01 100644 --- a/include/spdlog/sinks/ostream_sink.h +++ b/include/spdlog/sinks/ostream_sink.h @@ -3,6 +3,7 @@ #pragma once +#include "spdlog/common.h" #include "spdlog/details/null_mutex.h" #include "spdlog/sinks/base_sink.h" @@ -12,7 +13,7 @@ namespace spdlog { namespace sinks { template -class ostream_sink final : public base_sink +class SPDLOG_API ostream_sink final : public base_sink { public: explicit ostream_sink(std::ostream &os, bool force_flush = false) diff --git a/include/spdlog/sinks/rotating_file_sink.h b/include/spdlog/sinks/rotating_file_sink.h index f8c49e75..1ca01017 100644 --- a/include/spdlog/sinks/rotating_file_sink.h +++ b/include/spdlog/sinks/rotating_file_sink.h @@ -3,6 +3,7 @@ #pragma once +#include "spdlog/common.h" #include "spdlog/sinks/base_sink.h" #include "spdlog/details/file_helper.h" #include "spdlog/details/null_mutex.h" @@ -19,7 +20,7 @@ namespace sinks { // Rotating file sink based on size // template -class rotating_file_sink final : public base_sink +class SPDLOG_API rotating_file_sink final : public base_sink { public: rotating_file_sink(filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open = false); @@ -36,11 +37,11 @@ private: // log.1.txt -> log.2.txt // log.2.txt -> log.3.txt // log.3.txt -> delete - void rotate_(); + SPDLOG_PRIVATE void rotate_(); // delete the target if exists, and rename the src file to target // return true on success, false otherwise. - bool rename_file(const filename_t &src_filename, const filename_t &target_filename); + SPDLOG_PRIVATE bool rename_file(const filename_t &src_filename, const filename_t &target_filename); filename_t base_filename_; std::size_t max_size_; @@ -75,4 +76,4 @@ inline std::shared_ptr rotating_logger_st( #ifdef SPDLOG_HEADER_ONLY #include "rotating_file_sink-inl.h" -#endif \ No newline at end of file +#endif diff --git a/include/spdlog/sinks/sink.h b/include/spdlog/sinks/sink.h index 6515f1f1..c57ee87c 100644 --- a/include/spdlog/sinks/sink.h +++ b/include/spdlog/sinks/sink.h @@ -3,13 +3,14 @@ #pragma once +#include "spdlog/common.h" #include "spdlog/details/log_msg.h" #include "spdlog/formatter.h" namespace spdlog { namespace sinks { -class sink +class SPDLOG_API sink { public: virtual ~sink() = default; diff --git a/include/spdlog/sinks/stdout_color_sinks.h b/include/spdlog/sinks/stdout_color_sinks.h index d11ec0a1..a975558a 100644 --- a/include/spdlog/sinks/stdout_color_sinks.h +++ b/include/spdlog/sinks/stdout_color_sinks.h @@ -3,6 +3,8 @@ #pragma once +#include "spdlog/common.h" + #ifdef _WIN32 #include "spdlog/sinks/wincolor_sink.h" #else @@ -27,16 +29,16 @@ using stderr_color_sink_st = ansicolor_stderr_sink_st; } // namespace sinks template -std::shared_ptr stdout_color_mt(const std::string &logger_name, color_mode mode = color_mode::automatic); +SPDLOG_API std::shared_ptr stdout_color_mt(const std::string &logger_name, color_mode mode = color_mode::automatic); template -std::shared_ptr stdout_color_st(const std::string &logger_name, color_mode mode = color_mode::automatic); +SPDLOG_API std::shared_ptr stdout_color_st(const std::string &logger_name, color_mode mode = color_mode::automatic); template -std::shared_ptr stderr_color_mt(const std::string &logger_name, color_mode mode = color_mode::automatic); +SPDLOG_API std::shared_ptr stderr_color_mt(const std::string &logger_name, color_mode mode = color_mode::automatic); template -std::shared_ptr stderr_color_st(const std::string &logger_name, color_mode mode = color_mode::automatic); +SPDLOG_API std::shared_ptr stderr_color_st(const std::string &logger_name, color_mode mode = color_mode::automatic); } // namespace spdlog diff --git a/include/spdlog/sinks/stdout_sinks.h b/include/spdlog/sinks/stdout_sinks.h index 04d2fa42..2f9f541f 100644 --- a/include/spdlog/sinks/stdout_sinks.h +++ b/include/spdlog/sinks/stdout_sinks.h @@ -3,6 +3,7 @@ #pragma once +#include "spdlog/common.h" #include "spdlog/details/console_globals.h" #include "spdlog/details/synchronous_factory.h" #include "spdlog/sinks/sink.h" @@ -13,7 +14,7 @@ namespace spdlog { namespace sinks { template -class stdout_sink_base : public sink +class SPDLOG_API stdout_sink_base : public sink { public: using mutex_t = typename ConsoleMutex::mutex_t; @@ -35,14 +36,14 @@ protected: }; template -class stdout_sink : public stdout_sink_base +class SPDLOG_API stdout_sink : public stdout_sink_base { public: stdout_sink(); }; template -class stderr_sink : public stdout_sink_base +class SPDLOG_API stderr_sink : public stdout_sink_base { public: stderr_sink(); @@ -58,16 +59,16 @@ using stderr_sink_st = stderr_sink; // factory methods template -std::shared_ptr stdout_logger_mt(const std::string &logger_name); +SPDLOG_API std::shared_ptr stdout_logger_mt(const std::string &logger_name); template -std::shared_ptr stdout_logger_st(const std::string &logger_name); +SPDLOG_API std::shared_ptr stdout_logger_st(const std::string &logger_name); template -std::shared_ptr stderr_logger_mt(const std::string &logger_name); +SPDLOG_API std::shared_ptr stderr_logger_mt(const std::string &logger_name); template -std::shared_ptr stderr_logger_st(const std::string &logger_name); +SPDLOG_API std::shared_ptr stderr_logger_st(const std::string &logger_name); } // namespace spdlog diff --git a/include/spdlog/sinks/syslog_sink.h b/include/spdlog/sinks/syslog_sink.h index 43ffef6b..951eb380 100644 --- a/include/spdlog/sinks/syslog_sink.h +++ b/include/spdlog/sinks/syslog_sink.h @@ -3,6 +3,7 @@ #pragma once +#include "spdlog/common.h" #include "spdlog/sinks/base_sink.h" #include "spdlog/details/null_mutex.h" @@ -16,7 +17,7 @@ namespace sinks { * Sink that write to syslog using the `syscall()` library call. */ template -class syslog_sink : public base_sink +class SPDLOG_API syslog_sink : public base_sink { public: diff --git a/include/spdlog/sinks/systemd_sink.h b/include/spdlog/sinks/systemd_sink.h index d6516890..879c98b0 100644 --- a/include/spdlog/sinks/systemd_sink.h +++ b/include/spdlog/sinks/systemd_sink.h @@ -3,6 +3,7 @@ #pragma once +#include "spdlog/common.h" #include "spdlog/sinks/base_sink.h" #include "spdlog/details/null_mutex.h" #include "spdlog/details/synchronous_factory.h" @@ -18,7 +19,7 @@ namespace sinks { * Locking is not needed, as `sd_journal_send()` itself is thread-safe. */ template -class systemd_sink : public base_sink +class SPDLOG_API systemd_sink : public base_sink { public: // diff --git a/include/spdlog/sinks/wincolor_sink.h b/include/spdlog/sinks/wincolor_sink.h index 0ff43e07..b0492a25 100644 --- a/include/spdlog/sinks/wincolor_sink.h +++ b/include/spdlog/sinks/wincolor_sink.h @@ -21,7 +21,7 @@ namespace sinks { * colors */ template -class wincolor_sink : public sink +class SPDLOG_API wincolor_sink : public sink { public: const WORD BOLD = FOREGROUND_INTENSITY; @@ -65,14 +65,14 @@ protected: }; template -class wincolor_stdout_sink : public wincolor_sink +class SPDLOG_API wincolor_stdout_sink : public wincolor_sink { public: explicit wincolor_stdout_sink(color_mode mode = color_mode::automatic); }; template -class wincolor_stderr_sink : public wincolor_sink +class SPDLOG_API wincolor_stderr_sink : public wincolor_sink { public: explicit wincolor_stderr_sink(color_mode mode = color_mode::automatic); diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 4abb3098..ada751f2 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -46,52 +46,52 @@ inline std::shared_ptr create(std::string logger_name, SinkArgs // auto console_sink = std::make_shared(); // auto console_logger = std::make_shared("console_logger", console_sink); // spdlog::initialize_logger(console_logger); -void initialize_logger(std::shared_ptr logger); +SPDLOG_API void initialize_logger(std::shared_ptr logger); // Return an existing logger or nullptr if a logger with such name doesn't // exist. // example: spdlog::get("my_logger")->info("hello {}", "world"); -std::shared_ptr get(const std::string &name); +SPDLOG_API std::shared_ptr get(const std::string &name); // Set global formatter. Each sink in each logger will get a clone of this object -void set_formatter(std::unique_ptr formatter); +SPDLOG_API void set_formatter(std::unique_ptr formatter); // Set global format string. // example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v"); -void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local); +SPDLOG_API void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local); // Set global logging level -void set_level(level::level_enum log_level); +SPDLOG_API void set_level(level::level_enum log_level); // Set global flush level -void flush_on(level::level_enum log_level); +SPDLOG_API void flush_on(level::level_enum log_level); // Start/Restart a periodic flusher thread // Warning: Use only if all your loggers are thread safe! -void flush_every(std::chrono::seconds interval); +SPDLOG_API void flush_every(std::chrono::seconds interval); // Set global error handler -void set_error_handler(void (*handler)(const std::string &msg)); +SPDLOG_API void set_error_handler(void (*handler)(const std::string &msg)); // Register the given logger with the given name -void register_logger(std::shared_ptr logger); +SPDLOG_API void register_logger(std::shared_ptr logger); // Apply a user defined function on all registered loggers // Example: // spdlog::apply_all([&](std::shared_ptr l) {l->flush();}); -void apply_all(const std::function)> &fun); +SPDLOG_API void apply_all(const std::function)> &fun); // Drop the reference to the given logger -void drop(const std::string &name); +SPDLOG_API void drop(const std::string &name); // Drop all references from the registry -void drop_all(); +SPDLOG_API void drop_all(); // stop any running threads started by spdlog and clean registry loggers -void shutdown(); +SPDLOG_API void shutdown(); // Automatic registration of loggers when using spdlog::create() or spdlog::create_async -void set_automatic_registration(bool automatic_registation); +SPDLOG_API void set_automatic_registration(bool automatic_registation); // API for using default logger (stdout_color_mt), // e.g: spdlog::info("Message {}", 1); @@ -108,11 +108,11 @@ void set_automatic_registration(bool automatic_registation); // set_default_logger() *should not* be used concurrently with the default API. // e.g do not call set_default_logger() from one thread while calling spdlog::info() from another. -std::shared_ptr default_logger(); +SPDLOG_API std::shared_ptr default_logger(); -spdlog::logger *default_logger_raw(); +SPDLOG_API spdlog::logger *default_logger_raw(); -void set_default_logger(std::shared_ptr default_logger); +SPDLOG_API void set_default_logger(std::shared_ptr default_logger); template inline void log(source_loc source, level::level_enum lvl, string_view_t fmt, const Args &... args) diff --git a/src/spdlog.cpp b/src/spdlog.cpp index 956384f2..1ba78b56 100644 --- a/src/spdlog.cpp +++ b/src/spdlog.cpp @@ -105,6 +105,10 @@ template std::shared_ptr spdlog::stderr_logger_st