诸暨麻将添加redis
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

93 rader
2.4 KiB

  1. // Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
  2. // Distributed under the MIT License (http://opensource.org/licenses/MIT)
  3. #pragma once
  4. #ifndef SPDLOG_HEADER_ONLY
  5. #include <spdlog/async_logger.h>
  6. #endif
  7. #include <spdlog/sinks/sink.h>
  8. #include <spdlog/details/thread_pool.h>
  9. #include <memory>
  10. #include <string>
  11. SPDLOG_INLINE spdlog::async_logger::async_logger(
  12. std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
  13. : async_logger(std::move(logger_name), sinks_list.begin(), sinks_list.end(), std::move(tp), overflow_policy)
  14. {}
  15. SPDLOG_INLINE spdlog::async_logger::async_logger(
  16. std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
  17. : async_logger(std::move(logger_name), {std::move(single_sink)}, std::move(tp), overflow_policy)
  18. {}
  19. // send the log message to the thread pool
  20. SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg)
  21. {
  22. if (auto pool_ptr = thread_pool_.lock())
  23. {
  24. pool_ptr->post_log(shared_from_this(), msg, overflow_policy_);
  25. }
  26. else
  27. {
  28. SPDLOG_THROW(spdlog_ex("async log: thread pool doesn't exist anymore"));
  29. }
  30. }
  31. // send flush request to the thread pool
  32. SPDLOG_INLINE void spdlog::async_logger::flush_()
  33. {
  34. if (auto pool_ptr = thread_pool_.lock())
  35. {
  36. pool_ptr->post_flush(shared_from_this(), overflow_policy_);
  37. }
  38. else
  39. {
  40. SPDLOG_THROW(spdlog_ex("async flush: thread pool doesn't exist anymore"));
  41. }
  42. }
  43. //
  44. // backend functions - called from the thread pool to do the actual job
  45. //
  46. SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg &msg)
  47. {
  48. for (auto &sink : sinks_)
  49. {
  50. if (sink->should_log(msg.level))
  51. {
  52. SPDLOG_TRY
  53. {
  54. sink->log(msg);
  55. }
  56. SPDLOG_LOGGER_CATCH()
  57. }
  58. }
  59. if (should_flush_(msg))
  60. {
  61. backend_flush_();
  62. }
  63. }
  64. SPDLOG_INLINE void spdlog::async_logger::backend_flush_()
  65. {
  66. for (auto &sink : sinks_)
  67. {
  68. SPDLOG_TRY
  69. {
  70. sink->flush();
  71. }
  72. SPDLOG_LOGGER_CATCH()
  73. }
  74. }
  75. SPDLOG_INLINE std::shared_ptr<spdlog::logger> spdlog::async_logger::clone(std::string new_name)
  76. {
  77. auto cloned = std::make_shared<spdlog::async_logger>(*this);
  78. cloned->name_ = std::move(new_name);
  79. return cloned;
  80. }