HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_ErrorLog.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_ErrorLog.h (UT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __UT_ErrorLog__
12 #define __UT_ErrorLog__
13 
14 #include "UT_API.h"
15 #include <time.h>
16 #include "UT_SymbolTable.h"
17 #include "UT_String.h"
18 #include "UT_Lock.h"
19 
20 class UT_Error;
21 
23 {
24 public:
25  UT_ErrorLog();
26  ~UT_ErrorLog();
27 
28  /// Functor to handle errors printed out using the mantra* methods.
30  {
31  public:
33  /// The destructor automatically de-registers the callback
34  virtual ~ErrorCallback();
35 
36  /// If the method returns @c true, the error will not be printed out
37  /// by the built-in error handler. If it returns @c false, processing
38  /// continues in the normal way.
39  /// The @c level is the verbosity level of the error.
40  /// The built-in process will print out:
41  /// ("%s%s", prefix, message).
42  virtual bool filterError(int level,
43  const char *message,
44  const char *prefix) = 0;
45  };
46  /// If you want to un-register the callback, just delete the object.
47  static void registerCallback(ErrorCallback *err);
48 
49  // Log the error's description to the error file if its severity is greater
50  // than or equal to our minimum level
51  void logError(UT_Error *);
52 
53  // We only worry about locking when we set strings; we assume integers
54  // and booleans are atomic
55  const UT_String &getLogFileName() const
56  { return myLogFileName; }
58  {
59  myLock.lock();
60  myLogFileName.harden(name);
61  myLogFileName.expandVariables();
62  myLock.unlock();
63  }
64 
65  int getMinLevel() const
66  { return myMinLevel; }
67  void setMinLevel(const int level)
68  { myMinLevel = level; }
69 
70  bool getDoLogging() const
71  { return myDoLogging; }
72  void setDoLogging(bool log)
73  { myDoLogging = log; }
74 
75  void resetState()
76  {
77  myLock.lock();
78  myErrorLogTimes.clear();
79  myLock.unlock();
80  }
81 
82  // Callback function to check whether mantra verbosity is enabled for a
83  // particular callback level.
84  typedef int (*MantraVerboseCallback)(void);
85  typedef int (*MantraColorCallback)(void);
86  typedef bool (*MantraTimestampCallback)(void);
87 
88  // Set the verbosity level for mantra error messages. For any
89  // printouts to occur, it is necessary to first call this method with a
90  // non-negative value - otherwise calls to mantraPrintf, mantraWarning,
91  // and mantraError will be ignored. As an alternative, you can provide
92  // a callback that will dynamically update the verbosity level.
93  static void setMantraVerboseLevel(int level);
94  static int getMantraVerboseLevel();
95 
96  // This method will also cause errors and warnings to use a "mantra: "
97  // prefix.
98  static void setMantraVerboseCallback(MantraVerboseCallback cb);
99  static void setMantraColorCallback(MantraColorCallback cb);
100  static void setMantraTimestampCallback(MantraTimestampCallback cb);
101 
102  static int mantraPrintf(int level, const char *msg, ...)
104  static int mantraWarning(const char *msg, ...)
106  static int mantraError(const char *msg, ...)
107  SYS_PRINTF_CHECK_ATTRIBUTE(1,2);
108 
109  // Print the error message only if it has not been printed before
110  static int mantraPrintfOnce(int level, const char *msg, ...)
111  SYS_PRINTF_CHECK_ATTRIBUTE(2,3);
112  static int mantraWarningOnce(const char *msg, ...)
113  SYS_PRINTF_CHECK_ATTRIBUTE(1,2);
114  static int mantraErrorOnce(const char *msg, ...)
115  SYS_PRINTF_CHECK_ATTRIBUTE(1,2);
116 
117  // Clear tables of messages that have been printed before so that if
118  // an error recurs, it will be printed again.
119  static void clearMantraOnceErrors();
120 protected:
121 
122 private:
123  int myMinLevel;
124  UT_String myLogFileName;
125  bool myDoLogging;
126  UT_SymbolMap<time_t> myErrorLogTimes;
127  time_t myLastErrorTime;
128  UT_Lock myLock;
129 };
130 
132 
133 #endif
134 
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
void setMinLevel(const int level)
Definition: UT_ErrorLog.h:67
GLint level
Definition: glcorearb.h:107
UT_API UT_ErrorLog * UTgetErrorLog()
#define UT_API
Definition: UT_API.h:12
void resetState()
Definition: UT_ErrorLog.h:75
int getMinLevel() const
Definition: UT_ErrorLog.h:65
void setDoLogging(bool log)
Definition: UT_ErrorLog.h:72
SYS_API double log(double x)
const UT_String & getLogFileName() const
Definition: UT_ErrorLog.h:55
void setLogFileName(const UT_String &name)
Definition: UT_ErrorLog.h:57
#define SYS_PRINTF_CHECK_ATTRIBUTE(string_index, first_to_check)
Definition: SYS_Types.h:425
GLuint const GLchar * name
Definition: glcorearb.h:785
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2542
typedef int
Definition: png.h:1175
Functor to handle errors printed out using the mantra* methods.
Definition: UT_ErrorLog.h:29
#define const
Definition: zconf.h:214
bool getDoLogging() const
Definition: UT_ErrorLog.h:70