HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_UniversalLogEntry.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: UT_UniversalLogEntry.h ( FS Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UT_UniversalLogEntry__
13 #define __UT_UniversalLogEntry__
14 
15 #include "UT_API.h"
16 #include "UT_Date.h"
17 #include "UT_Error.h"
18 #include "UT_ErrorCode.h"
19 #include "UT_IntrusivePtr.h"
20 #include "UT_SourceLocation.h"
21 #include "UT_StringHolder.h"
22 #include <SYS/SYS_Hash.h>
23 #include <SYS/SYS_Math.h>
25 #include <SYS/SYS_Time.h>
26 
27 template <typename T> class UT_Array;
28 class UT_JSONParser;
29 class UT_JSONWriter;
30 
32  public UT_IntrusiveRefCounter<UT_UniversalLogExternalInfo>
33 {
34 public:
36  : myProcessId(0)
37  { }
38 
40  {
42  SYShashCombine(h, myIdentifier.hash());
43  SYShashCombine(h, myCommandLine.hash());
44  SYShashCombine(h, SYSwang_inthash(myProcessId));
45 
46  return h;
47  }
48 
53 };
56 
57 /// Simple object to hold the data associated with a single log entry event.
59 {
60 public:
64  const UT_StringHolder &source_context = UT_StringHolder::theEmptyString,
66  int verbosity = 0,
67  const UT_SourceLocation &source_code_location = UT_SourceLocation(),
68  UT_UniversalLogExternalInfoHandle external_info =
70  : mySourceName(source_name),
71  myMessage(message),
72  mySourceContext(source_context),
73  mySourceCodeLocation(source_code_location),
74  myErrorSeverity(severity),
75  myVerbosity(verbosity),
76  myTime(SYStime() - theStartTime + theStartTimeSinceEpoch),
77  myThreadId(SYSgetSTID()),
78  myExternalInfo(external_info)
79  { }
80 
82  const UT_ErrorCode &ec,
83  const UT_StringHolder &what,
84  const UT_StringHolder &source_context
87  int verbosity = 0,
88  const UT_SourceLocation &source_location = UT_SourceLocation(),
91  : mySourceName(ec.category().name())
92  , mySourceContext(source_context)
93  , mySourceCodeLocation(source_location)
94  , myErrorSeverity(severity)
95  , myVerbosity(verbosity)
96  , myTime(SYStime() - theStartTime + theStartTimeSinceEpoch)
97  , myThreadId(SYSgetSTID())
98  , myExternalInfo(external_info)
99  {
100  myMessage.format("{}: {}", what, ec.message());
101  }
102 
103  /// The natural order of log messages is chronological.
104  bool operator<(const UT_UniversalLogEntry &other) const
105  {
106  return myTime < other.myTime;
107  }
108 
110  {
111  return sizeof(*this) +
112  mySourceName.length() +
113  myMessage.length() +
114  mySourceContext.length() +
115  mySourceCodeLocation.getMemoryUsage(false);
116  }
117 
119  {
120  SYS_HashType h = mySourceName.hash();
121  SYShashCombine(h, myMessage.hash());
122  SYShashCombine(h, mySourceContext.hash());
123  SYShashCombine(h, mySourceCodeLocation.source().hash());
124  SYShashCombine(h, SYSwang_inthash(mySourceCodeLocation.line()));
125  SYShashCombine(h, SYSwang_inthash(mySourceCodeLocation.columnStart()));
126  SYShashCombine(h, SYSwang_inthash(mySourceCodeLocation.columnEnd()));
127  SYShashCombine(h, SYSwang_inthash(myErrorSeverity));
128  SYShashCombine(h, SYSwang_inthash(myVerbosity));
129  SYShashCombine(h, SYSreal_hash(myTime));
130  SYShashCombine(h, SYSwang_inthash(myThreadId));
131  if (myExternalInfo)
132  SYShashCombine(h, myExternalInfo->hash());
133 
134  return h;
135  }
136 
137  static bool save(UT_JSONWriter &w,
138  const UT_Array<UT_UniversalLogEntry> &log_entries);
139  static bool load(UT_JSONParser &p,
140  UT_Array<UT_UniversalLogEntry> &log_entries);
141 
153 };
155 
156 #endif
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2543
unsigned hash() const
int myThreadId
UT_StringHolder mySourceName
UT_UniversalLogEntry(const UT_StringHolder &source_name=UT_StringHolder::theEmptyString, const UT_StringHolder &message=UT_StringHolder::theEmptyString, const UT_StringHolder &source_context=UT_StringHolder::theEmptyString, UT_ErrorSeverity severity=UT_ERROR_NONE, int verbosity=0, const UT_SourceLocation &source_code_location=UT_SourceLocation(), UT_UniversalLogExternalInfoHandle external_info=UT_UniversalLogExternalInfoHandle())
SYS_HashType hash() const
int64 exint
Definition: SYS_Types.h:125
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
UT_ErrorSeverity
Definition: UT_Error.h:25
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
#define UT_API
Definition: UT_API.h:14
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
A reference counter base class for use with UT_IntrusivePtr.
UT_UniversalLogEntry(const UT_ErrorCode &ec, const UT_StringHolder &what, const UT_StringHolder &source_context=UT_StringHolder::theEmptyString, UT_ErrorSeverity severity=UT_ERROR_ABORT, int verbosity=0, const UT_SourceLocation &source_location=UT_SourceLocation(), UT_UniversalLogExternalInfoHandle external_info=UT_UniversalLogExternalInfoHandle())
static const UT_StringHolder theEmptyString
int myVerbosity
GLenum GLenum severity
Definition: glcorearb.h:2539
GLuint const GLchar * name
Definition: glcorearb.h:786
SYS_API fpreal SYStime()
UT_Array< UT_UniversalLogEntry > UT_UniversalLogEntryArray
UT_StringHolder mySourceContext
UT_UniversalLogExternalInfoHandle myExternalInfo
std::error_code UT_ErrorCode
Definition: UT_ErrorCode.h:20
exint getMemoryUsage() const
UT_SourceLocation mySourceCodeLocation
UT_StringHolder myMessage
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
SYS_API int SYSgetSTID()
fpreal64 fpreal
Definition: SYS_Types.h:277
static fpreal theStartTime
UT_IntrusivePtr< UT_UniversalLogExternalInfo > UT_UniversalLogExternalInfoHandle
fpreal myTime
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
static fpreal theStartTimeSinceEpoch
bool operator<(const UT_UniversalLogEntry &other) const
The natural order of log messages is chronological.
Simple object to hold the data associated with a single log entry event.
UT_ErrorSeverity myErrorSeverity