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