Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
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
24namespace hazelcast {
25
26class HAZELCAST_API logger
27{
28public:
32 enum class level;
33
34 using handler_type = std::function<
35 void(const std::string&, const std::string&, level, const std::string&)>;
36
37 logger(std::string instance_name,
38 std::string cluster_name,
39 level lvl,
40 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
51private:
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
59enum class logger::level : int
60{
61 all = (std::numeric_limits<int>::min)(),
62 finest = 300,
63 finer = 400,
64 fine = 500,
65 info = 800,
66 warning = 900,
67 severe = 1000,
68 off = (std::numeric_limits<int>::max)()
69};
70
71HAZELCAST_API std::ostream&
72operator<<(std::ostream&, logger::level level);
73
74} // namespace hazelcast
75
76#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
77#pragma warning(pop)
78#endif