ionLogger.h
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include "ionTypes.h"
12 #include "String.h"
13 
14 
15 namespace ion
16 {
17 
20  enum class ELogChannel
21  {
22  Error = 0,
23  Warn = 1,
24  Info = 2
25  };
26 
29  class Log
30  {
31 
32  public:
33 
34  class Output
35  {
36 
37  public:
38 
39  virtual void Write(ELogChannel const Channel, string const & Message) = 0;
40 
41  };
42 
43  class StandardOutput : public Output
44  {
45 
46  public:
47 
48  StandardOutput(std::ostream & Stream);
49  virtual void Write(ELogChannel const Channel, string const & Message);
50 
51  private:
52 
53  std::ostream & Stream;
54 
55  };
56 
57  class WindowsLogOutput : public Output
58  {
59 
60  public:
61 
62  virtual void Write(ELogChannel const Channel, string const & Message);
63 
64  };
65 
66  template <typename... Args>
67  static void Info(char const * const Format, Args const &... args)
68  {
69  Write(ELogChannel::Info, Format, args...);
70  }
71 
72  template <typename... Args>
73  static void Warn(char const * const Format, Args const &... args)
74  {
75  Write(ELogChannel::Warn, Format, args...);
76  }
77 
78  template <typename... Args>
79  static void Error(char const * const Format, Args const &... args)
80  {
81  Write(ELogChannel::Error, Format, args...);
82  }
83 
84  template <typename... Args>
85  static void Write(ELogChannel const Channel, char const * const Format, Args const &... args)
86  {
87 #ifndef _ION_CONFIG_SUPPRESS_LOG
88  WriteInternal(Channel, tfm::format(Format, args...));
89 #endif
90  }
91 
92  static vector<string> const & GetMessages();
93  static vector<string> const & GetMessages(ELogChannel const Which);
94  static vector<pair<string, int>> const & GetMessagesDetail(ELogChannel const Which);
95 
96  static void AddOutput(ELogChannel const Which, Output * Out);
97  static void AddOutputToAllChannels(Output * Out);
98  static void AddDefaultOutputs();
99 
100  static void Clear();
101 
102  protected:
103 
104  class Channel
105  {
106 
107  public:
108 
110  string Label;
111  vector<Output *> WriteTo;
112  vector<string> Messages;
113  vector<pair<string, int>> MessagesDetail;
114  unordered_map<string, int> MessageMap;
115 
116  Channel(ELogChannel const Which, string const & Label);
117 
119  bool WriteMessage(string const & ToWrite);
120 
121  vector<pair<string, int>> const & GetMessagesDetail();
122 
123  };
124 
125  static Channel & GetChannel(ELogChannel const Which);
126  static string GetChannelLabel(ELogChannel const Which);
127 
128  static void WriteInternal(ELogChannel const Which, std::string const & Message);
129  static vector<string> & AllLoggedMessages();
130 
131  };
132 
133 }
string Label
Definition: ionLogger.h:110
static void Info(char const *const Format, Args const &...args)
Definition: ionLogger.h:67
vector< pair< string, int > > MessagesDetail
Definition: ionLogger.h:113
ELogChannel const Which
Definition: ionLogger.h:109
vector< string > Messages
Definition: ionLogger.h:112
static void Write(ELogChannel const Channel, char const *const Format, Args const &...args)
Definition: ionLogger.h:85
Definition: ionLogger.h:104
vector< Output * > WriteTo
Definition: ionLogger.h:111
Definition: CCatmullRomAdvancedSplineInterpolator.h:7
Logging class.
Definition: ionLogger.h:29
Definition: ionLogger.h:34
ELogChannel
Channels used by Log.
Definition: ionLogger.h:20
Defines typedefs for integer and floating point types.
Definition: ionLogger.h:57
static void Warn(char const *const Format, Args const &...args)
Definition: ionLogger.h:73
static void Error(char const *const Format, Args const &...args)
Definition: ionLogger.h:79
Definition: ionLogger.h:43
unordered_map< string, int > MessageMap
Definition: ionLogger.h:114