Horizon
logger.hpp
1 #pragma once
2 #include <deque>
3 #include <functional>
4 #include <string>
5 #include <tuple>
6 
7 namespace horizon {
8 class Logger {
9 public:
10  enum class Level { DEBUG, INFO, WARNING, CRITICAL };
11  enum class Domain {
12  UNSPECIFIED,
13  BOARD,
14  SCHEMATIC,
15  BLOCK,
16  TOOL,
17  CORE,
18  CANVAS,
19  IMP,
20  IMPORT,
21  VERSION,
22  POOL_UPDATE,
23  PICTURE,
24  PART,
25  };
26 
27  Logger();
28  static Logger &get();
29  static std::string level_to_string(Level level);
30  static std::string domain_to_string(Domain domain);
31 
32  static void log_debug(const std::string &message, Domain domain = Domain::UNSPECIFIED,
33  const std::string &detail = "");
34  static void log_info(const std::string &message, Domain domain = Domain::UNSPECIFIED,
35  const std::string &detail = "");
36  static void log_warning(const std::string &message, Domain domain = Domain::UNSPECIFIED,
37  const std::string &detail = "");
38  static void log_critical(const std::string &message, Domain domain = Domain::UNSPECIFIED,
39  const std::string &detail = "");
40 
41  class Item {
42  public:
43  Item(uint64_t s, Level l, const std::string &msg, Domain dom = Domain::UNSPECIFIED, const std::string &det = "")
44  : seq(s), level(l), message(msg), domain(dom), detail(det)
45  {
46  }
47 
48  uint64_t seq;
49  Level level;
50  std::string message;
51  Domain domain = Domain::UNSPECIFIED;
52  std::string detail;
53  };
54 
55  typedef std::function<void(const Item &it)> log_handler_t;
56 
57  void log(Level level, const std::string &message, Domain domain = Domain::UNSPECIFIED,
58  const std::string &detail = "");
59  void set_log_handler(log_handler_t handler);
60 
61 private:
62  log_handler_t handler = nullptr;
63  std::deque<Item> buffer;
64  uint64_t seq = 0;
65 };
66 } // namespace horizon
Definition: logger.hpp:41
Definition: logger.hpp:8
zip_uint64_t uint64_t
zip_uint64_t_t typedef.
Definition: zip.hpp:108