诸暨麻将添加redis
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

104 lines
2.7 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. #include <spdlog/common.h>
  5. #include <spdlog/details/log_msg.h>
  6. #include <spdlog/details/os.h>
  7. #include <spdlog/formatter.h>
  8. #include <chrono>
  9. #include <ctime>
  10. #include <memory>
  11. #include <string>
  12. #include <vector>
  13. namespace spdlog {
  14. namespace details {
  15. // padding information.
  16. struct padding_info
  17. {
  18. enum pad_side
  19. {
  20. left,
  21. right,
  22. center
  23. };
  24. padding_info() = default;
  25. padding_info(size_t width, padding_info::pad_side side, bool truncate)
  26. : width_(width)
  27. , side_(side)
  28. , truncate_(truncate)
  29. , enabled_(true)
  30. {}
  31. bool enabled() const
  32. {
  33. return enabled_;
  34. }
  35. const size_t width_ = 0;
  36. const pad_side side_ = left;
  37. bool truncate_ = false;
  38. bool enabled_ = false;
  39. };
  40. class flag_formatter
  41. {
  42. public:
  43. explicit flag_formatter(padding_info padinfo)
  44. : padinfo_(padinfo)
  45. {}
  46. flag_formatter() = default;
  47. virtual ~flag_formatter() = default;
  48. virtual void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) = 0;
  49. protected:
  50. padding_info padinfo_;
  51. };
  52. } // namespace details
  53. class pattern_formatter final : public formatter
  54. {
  55. public:
  56. explicit pattern_formatter(
  57. std::string pattern, pattern_time_type time_type = pattern_time_type::local, std::string eol = spdlog::details::os::default_eol);
  58. // use default pattern is not given
  59. explicit pattern_formatter(pattern_time_type time_type = pattern_time_type::local, std::string eol = spdlog::details::os::default_eol);
  60. pattern_formatter(const pattern_formatter &other) = delete;
  61. pattern_formatter &operator=(const pattern_formatter &other) = delete;
  62. std::unique_ptr<formatter> clone() const override;
  63. void format(const details::log_msg &msg, memory_buf_t &dest) override;
  64. private:
  65. std::string pattern_;
  66. std::string eol_;
  67. pattern_time_type pattern_time_type_;
  68. std::tm cached_tm_;
  69. std::chrono::seconds last_log_secs_;
  70. std::vector<std::unique_ptr<details::flag_formatter>> formatters_;
  71. std::tm get_time_(const details::log_msg &msg);
  72. template<typename Padder>
  73. void handle_flag_(char flag, details::padding_info padding);
  74. // Extract given pad spec (e.g. %8X)
  75. // Advance the given it pass the end of the padding spec found (if any)
  76. // Return padding.
  77. details::padding_info handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end);
  78. void compile_pattern_(const std::string &pattern);
  79. };
  80. } // namespace spdlog
  81. #ifdef SPDLOG_HEADER_ONLY
  82. #include "pattern_formatter-inl.h"
  83. #endif