诸暨麻将添加redis
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

343 linhas
9.8 KiB

  1. // Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
  2. // Distributed under the MIT License (http://opensource.org/licenses/MIT)
  3. // spdlog main header file.
  4. // see example.cpp for usage example
  5. #ifndef SPDLOG_H
  6. #define SPDLOG_H
  7. #pragma once
  8. #include <spdlog/common.h>
  9. #include <spdlog/details/registry.h>
  10. #include <spdlog/logger.h>
  11. #include <spdlog/version.h>
  12. #include <spdlog/details/synchronous_factory.h>
  13. #include <chrono>
  14. #include <functional>
  15. #include <memory>
  16. #include <string>
  17. namespace spdlog {
  18. using default_factory = synchronous_factory;
  19. // Create and register a logger with a templated sink type
  20. // The logger's level, formatter and flush level will be set according the
  21. // global settings.
  22. //
  23. // Example:
  24. // spdlog::create<daily_file_sink_st>("logger_name", "dailylog_filename", 11, 59);
  25. template<typename Sink, typename... SinkArgs>
  26. inline std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs &&... sink_args)
  27. {
  28. return default_factory::create<Sink>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
  29. }
  30. // Initialize and register a logger,
  31. // formatter and flush level will be set according the global settings.
  32. //
  33. // NOTE:
  34. // Use this function when creating loggers manually.
  35. //
  36. // Example:
  37. // auto console_sink = std::make_shared<spdlog::sinks::stdout_sink_mt>();
  38. // auto console_logger = std::make_shared<spdlog::logger>("console_logger", console_sink);
  39. // spdlog::initialize_logger(console_logger);
  40. void initialize_logger(std::shared_ptr<logger> logger);
  41. // Return an existing logger or nullptr if a logger with such name doesn't
  42. // exist.
  43. // example: spdlog::get("my_logger")->info("hello {}", "world");
  44. std::shared_ptr<logger> get(const std::string &name);
  45. // Set global formatter. Each sink in each logger will get a clone of this object
  46. void set_formatter(std::unique_ptr<spdlog::formatter> formatter);
  47. // Set global format string.
  48. // example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v");
  49. void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local);
  50. // enable global backtrace support
  51. void enable_backtrace(size_t n_messages);
  52. // disable global backtrace support
  53. void disable_backtrace();
  54. // call dump backtrace on default logger
  55. void dump_backtrace();
  56. // Set global logging level
  57. void set_level(level::level_enum log_level);
  58. // Set global flush level
  59. void flush_on(level::level_enum log_level);
  60. // Start/Restart a periodic flusher thread
  61. // Warning: Use only if all your loggers are thread safe!
  62. void flush_every(std::chrono::seconds interval);
  63. // Set global error handler
  64. void set_error_handler(void (*handler)(const std::string &msg));
  65. // Register the given logger with the given name
  66. void register_logger(std::shared_ptr<logger> logger);
  67. // Apply a user defined function on all registered loggers
  68. // Example:
  69. // spdlog::apply_all([&](std::shared_ptr<spdlog::logger> l) {l->flush();});
  70. void apply_all(const std::function<void(std::shared_ptr<logger>)> &fun);
  71. // Drop the reference to the given logger
  72. void drop(const std::string &name);
  73. // Drop all references from the registry
  74. void drop_all();
  75. // stop any running threads started by spdlog and clean registry loggers
  76. void shutdown();
  77. // Automatic registration of loggers when using spdlog::create() or spdlog::create_async
  78. void set_automatic_registration(bool automatic_registration);
  79. // API for using default logger (stdout_color_mt),
  80. // e.g: spdlog::info("Message {}", 1);
  81. //
  82. // The default logger object can be accessed using the spdlog::default_logger():
  83. // For example, to add another sink to it:
  84. // spdlog::default_logger()->sinks()->push_back(some_sink);
  85. //
  86. // The default logger can replaced using spdlog::set_default_logger(new_logger).
  87. // For example, to replace it with a file logger.
  88. //
  89. // IMPORTANT:
  90. // The default API is thread safe (for _mt loggers), but:
  91. // set_default_logger() *should not* be used concurrently with the default API.
  92. // e.g do not call set_default_logger() from one thread while calling spdlog::info() from another.
  93. std::shared_ptr<spdlog::logger> default_logger();
  94. spdlog::logger *default_logger_raw();
  95. void set_default_logger(std::shared_ptr<spdlog::logger> default_logger);
  96. template<typename... Args>
  97. inline void log(source_loc source, level::level_enum lvl, string_view_t fmt, const Args &... args)
  98. {
  99. default_logger_raw()->log(source, lvl, fmt, args...);
  100. }
  101. template<typename... Args>
  102. inline void log(level::level_enum lvl, string_view_t fmt, const Args &... args)
  103. {
  104. default_logger_raw()->log(source_loc{}, lvl, fmt, args...);
  105. }
  106. template<typename... Args>
  107. inline void trace(string_view_t fmt, const Args &... args)
  108. {
  109. default_logger_raw()->trace(fmt, args...);
  110. }
  111. template<typename... Args>
  112. inline void debug(string_view_t fmt, const Args &... args)
  113. {
  114. default_logger_raw()->debug(fmt, args...);
  115. }
  116. template<typename... Args>
  117. inline void info(string_view_t fmt, const Args &... args)
  118. {
  119. default_logger_raw()->info(fmt, args...);
  120. }
  121. template<typename... Args>
  122. inline void warn(string_view_t fmt, const Args &... args)
  123. {
  124. default_logger_raw()->warn(fmt, args...);
  125. }
  126. template<typename... Args>
  127. inline void error(string_view_t fmt, const Args &... args)
  128. {
  129. default_logger_raw()->error(fmt, args...);
  130. }
  131. template<typename... Args>
  132. inline void critical(string_view_t fmt, const Args &... args)
  133. {
  134. default_logger_raw()->critical(fmt, args...);
  135. }
  136. template<typename T>
  137. inline void log(source_loc source, level::level_enum lvl, const T &msg)
  138. {
  139. default_logger_raw()->log(source, lvl, msg);
  140. }
  141. template<typename T>
  142. inline void log(level::level_enum lvl, const T &msg)
  143. {
  144. default_logger_raw()->log(lvl, msg);
  145. }
  146. template<typename T>
  147. inline void trace(const T &msg)
  148. {
  149. default_logger_raw()->trace(msg);
  150. }
  151. template<typename T>
  152. inline void debug(const T &msg)
  153. {
  154. default_logger_raw()->debug(msg);
  155. }
  156. template<typename T>
  157. inline void info(const T &msg)
  158. {
  159. default_logger_raw()->info(msg);
  160. }
  161. template<typename T>
  162. inline void warn(const T &msg)
  163. {
  164. default_logger_raw()->warn(msg);
  165. }
  166. template<typename T>
  167. inline void error(const T &msg)
  168. {
  169. default_logger_raw()->error(msg);
  170. }
  171. template<typename T>
  172. inline void critical(const T &msg)
  173. {
  174. default_logger_raw()->critical(msg);
  175. }
  176. #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
  177. template<typename... Args>
  178. inline void log(source_loc source, level::level_enum lvl, wstring_view_t fmt, const Args &... args)
  179. {
  180. default_logger_raw()->log(source, lvl, fmt, args...);
  181. }
  182. template<typename... Args>
  183. inline void log(level::level_enum lvl, wstring_view_t fmt, const Args &... args)
  184. {
  185. default_logger_raw()->log(lvl, fmt, args...);
  186. }
  187. template<typename... Args>
  188. inline void trace(wstring_view_t fmt, const Args &... args)
  189. {
  190. default_logger_raw()->trace(fmt, args...);
  191. }
  192. template<typename... Args>
  193. inline void debug(wstring_view_t fmt, const Args &... args)
  194. {
  195. default_logger_raw()->debug(fmt, args...);
  196. }
  197. template<typename... Args>
  198. inline void info(wstring_view_t fmt, const Args &... args)
  199. {
  200. default_logger_raw()->info(fmt, args...);
  201. }
  202. template<typename... Args>
  203. inline void warn(wstring_view_t fmt, const Args &... args)
  204. {
  205. default_logger_raw()->warn(fmt, args...);
  206. }
  207. template<typename... Args>
  208. inline void error(wstring_view_t fmt, const Args &... args)
  209. {
  210. default_logger_raw()->error(fmt, args...);
  211. }
  212. template<typename... Args>
  213. inline void critical(wstring_view_t fmt, const Args &... args)
  214. {
  215. default_logger_raw()->critical(fmt, args...);
  216. }
  217. #endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
  218. } // namespace spdlog
  219. //
  220. // enable/disable log calls at compile time according to global level.
  221. //
  222. // define SPDLOG_ACTIVE_LEVEL to one of those (before including spdlog.h):
  223. // SPDLOG_LEVEL_TRACE,
  224. // SPDLOG_LEVEL_DEBUG,
  225. // SPDLOG_LEVEL_INFO,
  226. // SPDLOG_LEVEL_WARN,
  227. // SPDLOG_LEVEL_ERROR,
  228. // SPDLOG_LEVEL_CRITICAL,
  229. // SPDLOG_LEVEL_OFF
  230. //
  231. #define SPDLOG_LOGGER_CALL(logger, level, ...) (logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__)
  232. #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
  233. #define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
  234. #define SPDLOG_TRACE(...) SPDLOG_LOGGER_TRACE(spdlog::default_logger_raw(), __VA_ARGS__)
  235. #else
  236. #define SPDLOG_LOGGER_TRACE(logger, ...) (void)0
  237. #define SPDLOG_TRACE(...) (void)0
  238. #endif
  239. #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG
  240. #define SPDLOG_LOGGER_DEBUG(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::debug, __VA_ARGS__)
  241. #define SPDLOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(spdlog::default_logger_raw(), __VA_ARGS__)
  242. #else
  243. #define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0
  244. #define SPDLOG_DEBUG(...) (void)0
  245. #endif
  246. #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO
  247. #define SPDLOG_LOGGER_INFO(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::info, __VA_ARGS__)
  248. #define SPDLOG_INFO(...) SPDLOG_LOGGER_INFO(spdlog::default_logger_raw(), __VA_ARGS__)
  249. #else
  250. #define SPDLOG_LOGGER_INFO(logger, ...) (void)0
  251. #define SPDLOG_INFO(...) (void)0
  252. #endif
  253. #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN
  254. #define SPDLOG_LOGGER_WARN(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__)
  255. #define SPDLOG_WARN(...) SPDLOG_LOGGER_WARN(spdlog::default_logger_raw(), __VA_ARGS__)
  256. #else
  257. #define SPDLOG_LOGGER_WARN(logger, ...) (void)0
  258. #define SPDLOG_WARN(...) (void)0
  259. #endif
  260. #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR
  261. #define SPDLOG_LOGGER_ERROR(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__)
  262. #define SPDLOG_ERROR(...) SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__)
  263. #else
  264. #define SPDLOG_LOGGER_ERROR(logger, ...) (void)0
  265. #define SPDLOG_ERROR(...) (void)0
  266. #endif
  267. #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL
  268. #define SPDLOG_LOGGER_CRITICAL(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__)
  269. #define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(spdlog::default_logger_raw(), __VA_ARGS__)
  270. #else
  271. #define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0
  272. #define SPDLOG_CRITICAL(...) (void)0
  273. #endif
  274. #ifdef SPDLOG_HEADER_ONLY
  275. #include "spdlog-inl.h"
  276. #endif
  277. #endif // SPDLOG_H