Hazelcast C++ Client
Hazelcast C++ Client Library
logger.h
1 #pragma once
2 
3 #include <string>
4 #include <functional>
5 #include <limits>
6 #include <mutex>
7 
8 #include "hazelcast/util/export.h"
9 
10 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
11 #pragma warning(push)
12 #pragma warning(disable: 4251) //for dll export
13 #endif
14 
15 #ifndef HZ_LOGGING_DISABLED
16 #define HZ_LOG(lg, lvl, msg) \
17  if ((lg).enabled( ::hazelcast::logger::level::lvl )) { \
18  (lg).log(::hazelcast::logger::level::lvl, ( msg )); \
19  }
20 #else
21  #define HZ_LOG(lg, lvl, msg)
22 #endif
23 
24 
25 namespace hazelcast {
26 
27 class HAZELCAST_API logger {
28 public:
32  enum class level;
33 
34  using handler_type = std::function<void(const std::string &,
35  const std::string &,
36  level,
37  const std::string &)>;
38 
39  logger(std::string instance_name, std::string cluster_name,
40  level lvl, handler_type handler);
41 
42  bool enabled(level lvl) noexcept;
43 
44  void log(level lvl, const std::string &msg) noexcept;
45 
46  static void default_handler(const std::string &instance_name,
47  const std::string &cluster_name,
48  level lvl,
49  const std::string &msg) noexcept;
50 
51 private:
52  const std::string instance_name_;
53  const std::string cluster_name_;
54  const level level_;
55  const handler_type handler_;
56  static std::mutex cout_lock_;
57 };
58 
59 enum class logger::level : int {
60  all = (std::numeric_limits<int>::min)(),
61  finest = 300,
62  finer = 400,
63  fine = 500,
64  info = 800,
65  warning = 900,
66  severe = 1000,
67  off = (std::numeric_limits<int>::max)()
68 };
69 
70 HAZELCAST_API std::ostream& operator<<(std::ostream&, logger::level level);
71 
72 } // namespace hazelcast
73 
74 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
75 #pragma warning(pop)
76 #endif