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 { UNSPECIFIED, BOARD, SCHEMATIC, BLOCK, TOOL, CORE, CANVAS, IMP, IMPORT };
12 
13  Logger();
14  static Logger &get();
15  static std::string level_to_string(Level level);
16  static std::string domain_to_string(Domain domain);
17 
18  static void log_debug(const std::string &message, Domain domain = Domain::UNSPECIFIED,
19  const std::string &detail = "");
20  static void log_info(const std::string &message, Domain domain = Domain::UNSPECIFIED,
21  const std::string &detail = "");
22  static void log_warning(const std::string &message, Domain domain = Domain::UNSPECIFIED,
23  const std::string &detail = "");
24  static void log_critical(const std::string &message, Domain domain = Domain::UNSPECIFIED,
25  const std::string &detail = "");
26 
27  class Item {
28  public:
29  Item(uint64_t s, Level l, const std::string &msg, Domain dom = Domain::UNSPECIFIED, const std::string &det = "")
30  : seq(s), level(l), message(msg), domain(dom), detail(det)
31  {
32  }
33 
34  uint64_t seq;
35  Level level;
36  std::string message;
37  Domain domain = Domain::UNSPECIFIED;
38  std::string detail;
39  };
40 
41  typedef std::function<void(const Item &it)> log_handler_t;
42 
43  void log(Level level, const std::string &message, Domain domain = Domain::UNSPECIFIED,
44  const std::string &detail = "");
45  void set_log_handler(log_handler_t handler);
46 
47 private:
48  log_handler_t handler = nullptr;
49  std::deque<Item> buffer;
50  uint64_t seq = 0;
51 };
52 } // namespace horizon
horizon::Logger::Item
Definition: logger.hpp:27
libzip::uint64_t
zip_uint64_t uint64_t
zip_uint64_t_t typedef.
Definition: zip.hpp:108
horizon::Logger
Definition: logger.hpp:8