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  PROJECT,
26  BLOCKS,
27  };
28 
29  Logger();
30  static Logger &get();
31  static std::string level_to_string(Level level);
32  static std::string domain_to_string(Domain domain);
33 
34  static void log_debug(const std::string &message, Domain domain = Domain::UNSPECIFIED,
35  const std::string &detail = "");
36  static void log_info(const std::string &message, Domain domain = Domain::UNSPECIFIED,
37  const std::string &detail = "");
38  static void log_warning(const std::string &message, Domain domain = Domain::UNSPECIFIED,
39  const std::string &detail = "");
40  static void log_critical(const std::string &message, Domain domain = Domain::UNSPECIFIED,
41  const std::string &detail = "");
42 
43  class Item {
44  public:
45  Item(uint64_t s, Level l, const std::string &msg, Domain dom = Domain::UNSPECIFIED, const std::string &det = "")
46  : seq(s), level(l), message(msg), domain(dom), detail(det)
47  {
48  }
49 
50  uint64_t seq;
51  Level level;
52  std::string message;
53  Domain domain = Domain::UNSPECIFIED;
54  std::string detail;
55  };
56 
57  typedef std::function<void(const Item &it)> log_handler_t;
58 
59  void log(Level level, const std::string &message, Domain domain = Domain::UNSPECIFIED,
60  const std::string &detail = "");
61  void set_log_handler(log_handler_t handler);
62 
63 private:
64  log_handler_t handler = nullptr;
65  std::deque<Item> buffer;
66  uint64_t seq = 0;
67 };
68 } // namespace horizon
Definition: logger.hpp:43
Definition: logger.hpp:8
zip_uint64_t uint64_t
zip_uint64_t_t typedef.
Definition: zip.hpp:108