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  * PROPRIETARY 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 
19 
22 
23 /// Both logs and keeps track of logged entries. This is mostly useful if you
24 /// need to keep track of all logged messages. As an example, HTTP api requests
25 /// need to be logged but also collected so they can be sent back to the client.
27 {
28 public:
30  myTrackLogs(true)
31  {}
32 
33  template <typename... Args>
34  void logMessage(
35  const UT_StringHolder& source_name,
36  const char* fmt,
37  Args&&... args)
38  {
39  UT_StringHolder msg;
40  msg.format(fmt, std::forward<Args>(args)...);
41  logEntry(UT_UniversalLogEntry(source_name, msg, "", UT_ERROR_MESSAGE));
42  }
43  template <typename... Args>
44  void logPrompt(
45  const UT_StringHolder& source_name,
46  const char* fmt,
47  Args&&... args)
48  {
49  UT_StringHolder msg;
50  msg.format(fmt, std::forward<Args>(args)...);
51  logEntry(UT_UniversalLogEntry(source_name, msg, "", UT_ERROR_PROMPT));
52  }
53  template <typename... Args>
54  void logWarning(
55  const UT_StringHolder& source_name,
56  const char* fmt,
57  Args&&... args)
58  {
59  UT_StringHolder msg;
60  msg.format(fmt, std::forward<Args>(args)...);
61  logEntry(UT_UniversalLogEntry(source_name, msg, "", UT_ERROR_WARNING));
62  }
63  template <typename... Args>
64  void logError(
65  const UT_StringHolder& source_name,
66  const char* fmt,
67  Args&&... args)
68  {
69  UT_StringHolder msg;
70  msg.format(fmt, std::forward<Args>(args)...);
71  logEntry(UT_UniversalLogEntry(source_name, msg, "", UT_ERROR_ABORT));
72  }
73  template <typename... Args>
74  void logFatal(
75  const UT_StringHolder& source_name,
76  const char* fmt,
77  Args&&... args)
78  {
79  UT_StringHolder msg;
80  msg.format(fmt, std::forward<Args>(args)...);
81  logEntry(UT_UniversalLogEntry(source_name, msg, "", UT_ERROR_FATAL));
82  }
83  void logEntry(const UT_UniversalLogEntry& entry)
84  {
85  NETsendLogEntry(entry);
86 
87  if (!myTrackLogs)
88  return;
89  myLogs.emplace_back(entry);
90  }
91 
92  const UT_UniversalLogEntryArray& logs() const { return myLogs; }
93  void clear() { myLogs.clear(); }
94 
95  void setTrackLogs(bool track) { myTrackLogs = track; }
96  SYS_NO_DISCARD_RESULT bool isTrackingLogs() const { return myTrackLogs; }
97 
98  void generateMessage(
101 
103  {
104  return myLogs.isEmpty();
105  }
106 private:
107  bool myTrackLogs;
109 };
110 
111 // -----------------------------------------------------------------------------
112 // Adds logs to the provided log manager.
113 // -----------------------------------------------------------------------------
114 
115 template <typename... Args>
116 void
118  NET_LogManager& mgr,
119  const UT_StringHolder& context,
120  const char* fmt,
121  Args&&... args)
122 {
123  UT_StringHolder msg;
124  msg.format(fmt, std::forward<Args>(args)...);
126  NETsourceName(), msg, context, UT_ERROR_MESSAGE));
127 }
128 template <typename... Args>
129 void
131  NET_LogManager& mgr,
132  const UT_StringHolder& context,
133  const char* fmt,
134  Args&&... args)
135 {
136  UT_StringHolder msg;
137  msg.format(fmt, std::forward<Args>(args)...);
139  NETsourceName(), msg, context, UT_ERROR_PROMPT));
140 }
141 
142 template <typename... Args>
143 void
145  NET_LogManager& mgr,
146  const UT_StringHolder& context,
147  const char* fmt,
148  Args&&... args)
149 {
150  UT_StringHolder msg;
151  msg.format(fmt, std::forward<Args>(args)...);
153  NETsourceName(), msg, context, UT_ERROR_WARNING));
154 }
155 
156 template <typename... Args>
157 void
159  NET_LogManager& mgr,
160  const UT_StringHolder& context,
161  const char* fmt,
162  Args&&... args)
163 {
164  UT_StringHolder msg;
165  msg.format(fmt, std::forward<Args>(args)...);
167  NETsourceName(), msg, context, UT_ERROR_ABORT));
168 }
169 
170 template <typename... Args>
171 void
173  NET_LogManager& mgr,
174  const UT_StringHolder& context,
175  const char* fmt,
176  Args&&... args)
177 {
178  UT_StringHolder msg;
179  msg.format(fmt, std::forward<Args>(args)...);
181  NETsourceName(), msg, context, UT_ERROR_FATAL));
182 }
183 
184 // -----------------------------------------------------------------------------
185 // Adds errors to general error manager.
186 // -----------------------------------------------------------------------------
187 
188 template <typename... Args>
189 void
190 NETlogMessage(const UT_StringHolder& context, const char* fmt, Args&&... args)
191 {
192  UT_StringHolder msg;
193  msg.format(fmt, std::forward<Args>(args)...);
195  NETsourceName(), msg, context, UT_ERROR_MESSAGE));
196 }
197 template <typename... Args>
198 void
199 NETlogPrompt(const UT_StringHolder& context, const char* fmt, Args&&... args)
200 {
201  UT_StringHolder msg;
202  msg.format(fmt, std::forward<Args>(args)...);
204  NETsourceName(), msg, context, UT_ERROR_PROMPT));
205 }
206 
207 template <typename... Args>
208 void
209 NETlogWarning(const UT_StringHolder& context, const char* fmt, Args&&... args)
210 {
211  UT_StringHolder msg;
212  msg.format(fmt, std::forward<Args>(args)...);
214  NETsourceName(), msg, context, UT_ERROR_WARNING));
215 }
216 
217 template <typename... Args>
218 void
219 NETlogError(const UT_StringHolder& context, const char* fmt, Args&&... args)
220 {
221  UT_StringHolder msg;
222  msg.format(fmt, std::forward<Args>(args)...);
224  NETsourceName(), msg, context, UT_ERROR_ABORT));
225 }
226 
227 template <typename... Args>
228 void
229 NETlogFatal(const UT_StringHolder& context, const char* fmt, Args&&... args)
230 {
231  UT_StringHolder msg;
232  msg.format(fmt, std::forward<Args>(args)...);
234  NETsourceName(), msg, context, UT_ERROR_FATAL));
235 }
236 
237 #endif // __NET_UNIVERSALLOGNETWORKINGSOURCE_H__
238 
NET_API const UT_StringHolder & NETsourceName()
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2543
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:609
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)