HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NET_UniversalLogNetworkingSource.h
Go to the documentation of this file.
1 /*
2  * POPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: NET_UniversalLogNetworkingSource.h
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __NET_UNIVERSALLOGNETWORKINGSOURCE_H__
13 #define __NET_UNIVERSALLOGNETWORKINGSOURCE_H__
14 
15 #include "NET_API.h"
16 
18 
21 
22 /// Both logs and keeps track of logged entries. This is mostly useful if you
23 /// need to keep track of all logged messages. As an example, HTTP api requests
24 /// need to be logged but also collected so they can be sent back to the client.
26 {
27 public:
29  myTrackLogs(true)
30  {}
31 
32  template <typename... Args>
33  void logMessage(
34  const UT_StringHolder& source_name,
35  const char* fmt,
36  Args&&... args)
37  {
38  UT_StringHolder msg;
39  msg.format(fmt, std::forward<Args>(args)...);
40  logEntry(UT_UniversalLogEntry(source_name, msg, "", UT_ERROR_MESSAGE));
41  }
42  template <typename... Args>
43  void logPrompt(
44  const UT_StringHolder& source_name,
45  const char* fmt,
46  Args&&... args)
47  {
48  UT_StringHolder msg;
49  msg.format(fmt, std::forward<Args>(args)...);
50  logEntry(UT_UniversalLogEntry(source_name, msg, "", UT_ERROR_PROMPT));
51  }
52  template <typename... Args>
53  void logWarning(
54  const UT_StringHolder& source_name,
55  const char* fmt,
56  Args&&... args)
57  {
58  UT_StringHolder msg;
59  msg.format(fmt, std::forward<Args>(args)...);
60  logEntry(UT_UniversalLogEntry(source_name, msg, "", UT_ERROR_WARNING));
61  }
62  template <typename... Args>
63  void logError(
64  const UT_StringHolder& source_name,
65  const char* fmt,
66  Args&&... args)
67  {
68  UT_StringHolder msg;
69  msg.format(fmt, std::forward<Args>(args)...);
70  logEntry(UT_UniversalLogEntry(source_name, msg, "", UT_ERROR_ABORT));
71  }
72  template <typename... Args>
73  void logFatal(
74  const UT_StringHolder& source_name,
75  const char* fmt,
76  Args&&... args)
77  {
78  UT_StringHolder msg;
79  msg.format(fmt, std::forward<Args>(args)...);
80  logEntry(UT_UniversalLogEntry(source_name, msg, "", UT_ERROR_FATAL));
81  }
82  void logEntry(const UT_UniversalLogEntry& entry)
83  {
84  NETsendLogEntry(entry);
85 
86  if (!myTrackLogs)
87  return;
88  myLogs.emplace_back(entry);
89  }
90 
91  const UT_UniversalLogEntryArray& logs() const { return myLogs; }
92  void clear() { myLogs.clear(); }
93 
94  void setTrackLogs(bool track) { myTrackLogs = track; }
95  SYS_NO_DISCARD_RESULT bool isTrackingLogs() const { return myTrackLogs; }
96 
97  void generateMessage(
100 
102  {
103  return myLogs.isEmpty();
104  }
105 private:
106  bool myTrackLogs;
108 };
109 
110 // -----------------------------------------------------------------------------
111 // Adds logs to the provided log manager.
112 // -----------------------------------------------------------------------------
113 
114 template <typename... Args>
115 void
117  NET_LogManager& mgr,
118  const UT_StringHolder& context,
119  const char* fmt,
120  Args&&... args)
121 {
122  UT_StringHolder msg;
123  msg.format(fmt, std::forward<Args>(args)...);
125  NETsourceName(), msg, context, UT_ERROR_MESSAGE));
126 }
127 template <typename... Args>
128 void
130  NET_LogManager& mgr,
131  const UT_StringHolder& context,
132  const char* fmt,
133  Args&&... args)
134 {
135  UT_StringHolder msg;
136  msg.format(fmt, std::forward<Args>(args)...);
138  NETsourceName(), msg, context, UT_ERROR_PROMPT));
139 }
140 
141 template <typename... Args>
142 void
144  NET_LogManager& mgr,
145  const UT_StringHolder& context,
146  const char* fmt,
147  Args&&... args)
148 {
149  UT_StringHolder msg;
150  msg.format(fmt, std::forward<Args>(args)...);
152  NETsourceName(), msg, context, UT_ERROR_WARNING));
153 }
154 
155 template <typename... Args>
156 void
158  NET_LogManager& mgr,
159  const UT_StringHolder& context,
160  const char* fmt,
161  Args&&... args)
162 {
163  UT_StringHolder msg;
164  msg.format(fmt, std::forward<Args>(args)...);
166  NETsourceName(), msg, context, UT_ERROR_ABORT));
167 }
168 
169 template <typename... Args>
170 void
172  NET_LogManager& mgr,
173  const UT_StringHolder& context,
174  const char* fmt,
175  Args&&... args)
176 {
177  UT_StringHolder msg;
178  msg.format(fmt, std::forward<Args>(args)...);
180  NETsourceName(), msg, context, UT_ERROR_FATAL));
181 }
182 
183 // -----------------------------------------------------------------------------
184 // Adds errors to general error manager.
185 // -----------------------------------------------------------------------------
186 
187 template <typename... Args>
188 void
189 NETlogMessage(const UT_StringHolder& context, const char* fmt, Args&&... args)
190 {
191  UT_StringHolder msg;
192  msg.format(fmt, std::forward<Args>(args)...);
194  NETsourceName(), msg, context, UT_ERROR_MESSAGE));
195 }
196 template <typename... Args>
197 void
198 NETlogPrompt(const UT_StringHolder& context, const char* fmt, Args&&... args)
199 {
200  UT_StringHolder msg;
201  msg.format(fmt, std::forward<Args>(args)...);
203  NETsourceName(), msg, context, UT_ERROR_PROMPT));
204 }
205 
206 template <typename... Args>
207 void
208 NETlogWarning(const UT_StringHolder& context, const char* fmt, Args&&... args)
209 {
210  UT_StringHolder msg;
211  msg.format(fmt, std::forward<Args>(args)...);
213  NETsourceName(), msg, context, UT_ERROR_WARNING));
214 }
215 
216 template <typename... Args>
217 void
218 NETlogError(const UT_StringHolder& context, const char* fmt, Args&&... args)
219 {
220  UT_StringHolder msg;
221  msg.format(fmt, std::forward<Args>(args)...);
223  NETsourceName(), msg, context, UT_ERROR_ABORT));
224 }
225 
226 template <typename... Args>
227 void
228 NETlogFatal(const UT_StringHolder& context, const char* fmt, Args&&... args)
229 {
230  UT_StringHolder msg;
231  msg.format(fmt, std::forward<Args>(args)...);
233  NETsourceName(), msg, context, UT_ERROR_FATAL));
234 }
235 
236 #endif // __NET_UNIVERSALLOGNETWORKINGSOURCE_H__
237 
NET_API const UT_StringHolder & NETsourceName()
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2542
void NETlogPrompt(NET_LogManager &mgr, const UT_StringHolder &context, const char *fmt, Args &&...args)
void logMessage(const UT_StringHolder &source_name, const char *fmt, Args &&...args)
UT_ErrorSeverity
Definition: UT_Error.h:25
void logError(const UT_StringHolder &source_name, const char *fmt, Args &&...args)
void NETlogMessage(NET_LogManager &mgr, const UT_StringHolder &context, const char *fmt, Args &&...args)
const UT_UniversalLogEntryArray & logs() const
#define NET_API
Definition: NET_API.h:9
void NETlogFatal(NET_LogManager &mgr, const UT_StringHolder &context, const char *fmt, Args &&...args)
void logPrompt(const UT_StringHolder &source_name, const char *fmt, Args &&...args)
#define SYS_NO_DISCARD_RESULT
Definition: SYS_Compiler.h:93
size_t format(const char *fmt, const Args &...args)
Format a string using the same formatting codes as UTformat.
void logEntry(const UT_UniversalLogEntry &entry)
void NETlogWarning(NET_LogManager &mgr, const UT_StringHolder &context, const char *fmt, Args &&...args)
void logWarning(const UT_StringHolder &source_name, const char *fmt, Args &&...args)
SYS_NO_DISCARD_RESULT bool isEmpty() const
**If you just want to fire and args
Definition: thread.h:615
SYS_NO_DISCARD_RESULT bool isTrackingLogs() const
void NETlogError(NET_LogManager &mgr, const UT_StringHolder &context, const char *fmt, Args &&...args)
Simple object to hold the data associated with a single log entry event.
NET_API void NETsendLogEntry(const UT_UniversalLogEntry &entry)
void logFatal(const UT_StringHolder &source_name, const char *fmt, Args &&...args)