Utilities
Utilities header only library
LogEntry.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef UTILS_LOG_ENTRY_H
7 #define UTILS_LOG_ENTRY_H
8 #include <string>
9 #include <vector>
10 #include <Utils/API.h>
11 #include <Utils/Time.h>
12 
13 
14 namespace utils
15 {
16 
18  class UTILS_API LogEntry
19  {
20  public:
22  enum class Type
23  {
24  debug, // debug entry
25  info, // informative entry
26  warning, // warning entry of an invalid action, input or caller state
27  error, // a valid application state to report an error detected by the caller - will not affect the correct functioning of a program
28  critical, // an invalid application state that may cause the program to crash
29  _unspecified
30  };
31 
32  static std::vector<Type> GetWECTypes();
33 
34  static std::vector<Type> GetIWECTypes();
35 
36  explicit LogEntry(const std::string &message);
37 
38  LogEntry(Type type, const std::string &message, const std::string &caller_name);
39 
40  [[nodiscard]] static std::string TypeToString(Type type);
41  [[nodiscard]] static std::wstring TypeToWstring(Type type);
42 
43  [[nodiscard]] Type GetType() const;
44 
45  [[nodiscard]] const std::string &GetMessage() const;
46 
47  [[nodiscard]] const std::string &GetCaller() const;
48 
50  friend std::ostream &operator<< (std::ostream &os, const LogEntry &entry)
51  {
52  return os << entry.ToString();
53  }
54 
56  friend std::ostream &operator << (std::ostream &os, const std::vector<LogEntry> &v)
57  {
58  for (typename std::vector<LogEntry>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
59  {
60  os << *ii << "\n";
61  }
62  return os;
63  }
64 
66  friend std::ostream &operator << (std::ostream &os, const std::vector<std::shared_ptr<LogEntry>> &v)
67  {
68  for (typename std::vector<std::shared_ptr<LogEntry>>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
69  {
70  os << **ii << "\n";
71  }
72  return os;
73  }
74 
79  [[nodiscard]] virtual std::string ToString(const std::string &time_format = "%Y-%m-%d %H:%M:%S") const;
80 
81  [[nodiscard]] bool IsRead() const;
82 
84  void Read();
85 
86  private:
87  Type type_;
88  std::string message_;
89  std::string caller_name_;
90  time_m::DateTime time_;
91  bool is_read_;
92  };
93 
94 }
95 
96 #endif /* !UTILS_LOG_ENTRY_H */
virtual std::string ToString(const std::string &time_format="%Y-%m-%d %H:%M:%S") const
Print the entry to a string.
A single entry for the logging system.
Definition: LogEntry.h:18
General namespace for utilities.
Definition: BulletConversions.h:9
Type
Defines the character of a LogEntry.
Definition: LogEntry.h:22