Utilities
Utilities header only library
Ulog.h
1 #ifndef UTILS_ULOG_H
2 #define UTILS_ULOG_H
3 #include <Utils/API.h>
4 #include <Utils/LogEntry.h>
5 #include <Utils/StrongType.h>
6 #include <Utils/AtomicQueue.h>
7 
8 namespace ulog
9 {
11 
12  static const Category DEFAULT_CATEGORY{ "Default" };
13 
14 
15 
16  class UTILS_API Entry : public utils::LogEntry
17  {
18  public:
19  Entry(Type type, Category categ, const std::string &msg, const std::string &caller);
20  [[nodiscard]] Category GetCategory() const;
21  [[nodiscard]] std::string ToString(const std::string &time_format = "%Y-%m-%d %H:%M:%S") const override;
22  private:
23  Category category_;
24  };
25 
26 
27 
29  class LogHandler
30  {
31  public:
33  virtual void AddMessage(ulog::Entry::Type type, ulog::Category categ, const std::string &msg, const std::string &caller) = 0;
34  };
35 
37  class UTILS_API PoolLogHandler : public LogHandler
38  {
39  public:
41  void AddMessage(ulog::Entry::Type type, ulog::Category categ, const std::string &msg, const std::string &caller) override;
43  void ProcessEntries(std::function<void(const ulog::Entry &)> func);
45  size_t GetEntryCount() const;
46  private:
48  };
49 
51  class UTILS_API IgnorantHandler : public LogHandler
52  {
53  public:
54  IgnorantHandler() = default;
56  IgnorantHandler(ulog::Entry::Type maximal_ignored_type);
58  void AddMessage(ulog::Entry::Type, ulog::Category, const std::string &, const std::string &) override;
59  private:
60  ulog::Entry::Type maximal_ignored_type_ = ulog::Entry::Type::info;
61  };
62 
64  UTILS_API void InstallHandler(const std::shared_ptr<LogHandler> &sink_to_use);
65 
67  UTILS_API void ResetHandler();
68 
70  UTILS_API void Debug(const std::string &msg, const std::string &caller = "");
71 
73  UTILS_API void Info(const std::string &msg, const std::string &caller = "");
74 
76  UTILS_API void Warn(const std::string &msg, const std::string &caller = "");
77 
79  UTILS_API void Fail(const std::string &msg, const std::string &caller = "");
80 
82  UTILS_API void Crash(const std::string &msg, const std::string &caller = "");
83 
84 
85 
87  UTILS_API void DebugC(Category msg_category, const std::string &msg, const std::string &caller = "");
88 
90  UTILS_API void InfoC(Category msg_category, const std::string &msg, const std::string &caller = "");
91 
93  UTILS_API void WarnC(Category msg_category, const std::string &msg, const std::string &caller = "");
94 
96  UTILS_API void FailC(Category msg_category, const std::string &msg, const std::string &caller = "");
97 
99  UTILS_API void CrashC(Category msg_category, const std::string &msg, const std::string &caller = "");
100 
101 }
102 
103 
104 #endif /* !UTILS_ULOG_H */
Definition: Ulog.h:8
Stores log messages in a pool to be processed later.
Definition: Ulog.h:37
Abstract class that can be inherited to create custom log message behavior.
Definition: Ulog.h:29
A single entry for the logging system.
Definition: LogEntry.h:18
std::string ToString(const std::vector< T > &container, const std::string &separator=", ")
Converts all values in the vector to a string and joins them using specified separator.
Definition: ExtSTD.h:233
Contains common lambda functions.
Definition: Functional.h:12
Type
Defines the character of a LogEntry.
Definition: LogEntry.h:22
Log handler that ignores and discards all log messages.
Definition: Ulog.h:51