Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.9 KiB

  1. //#pragma title( "Err.hpp - Basic error handling/message/logging" )
  2. /*
  3. Copyright (c) 1995-1998, Mission Critical Software, Inc. All rights reserved.
  4. ===============================================================================
  5. Module - Err.hpp
  6. System - Common
  7. Author - Tom Bernhardt, Rich Denham
  8. Created - 1994-08-22
  9. Description - Implements the TError class that handles basic exception
  10. handling, message generation, and logging functions.
  11. Updates - 1997-09-12 RED replace TTime class
  12. ===============================================================================
  13. */
  14. #ifndef MCSINC_Err_hpp
  15. #define MCSINC_Err_hpp
  16. // Start of header file dependencies
  17. #ifndef MCSINC_Common_hpp
  18. #include "Common.hpp"
  19. #endif
  20. // End of header file dependencies
  21. // ErrMsg error level constants
  22. #define ErrT (00000 - __LINE__) // Testing
  23. #define ErrI (00000) // Information
  24. #define ErrW (10000) // Warning
  25. #define ErrE (20000) // Error
  26. #define ErrS (30000) // Severe error
  27. #define ErrV (40000) // Very sever error
  28. #define ErrU (50000) // Unrecoverable error
  29. #define ErrX (60000) // extremely unrecoverable <g>
  30. #define ErrNone (0)
  31. class TError
  32. {
  33. protected:
  34. int level;
  35. int lastError;
  36. int maxError;
  37. int logLevel; // minimum level to log
  38. int dispLevel; // minimum level to display
  39. FILE * logFile;
  40. int beepLevel;
  41. public:
  42. TError(
  43. int displevel = 0,// in -mimimum severity level to display
  44. int loglevel = 0 ,// in -mimimum severity level to log
  45. WCHAR const * filename = L"",// in -file name of log (NULL if none)
  46. int logmode = 0 ,// in -0=replace, 1=append
  47. int beeplevel = 100 // in -min error level for beeping
  48. // Some people dont like the beeps so we turned it off by default.
  49. );
  50. ~TError();
  51. void __cdecl MsgWrite(
  52. int num ,// in -error number/level code
  53. WCHAR const msg[] ,// in -error message to display
  54. ... // in -printf args to msg pattern
  55. );
  56. #ifndef WIN16_VERSION
  57. void __cdecl SysMsgWrite(
  58. int num ,// in -error number/level code
  59. DWORD lastRc ,// in -error return code
  60. WCHAR const msg[] ,// in -error message/pattern to display
  61. ... // in -printf args to msg pattern
  62. );
  63. void __cdecl SysMsgWrite(
  64. int num ,// in -error number/level code
  65. WCHAR const msg[] ,// in -error message/pattern to display
  66. ... // in -printf args to msg pattern
  67. );
  68. #endif
  69. void __stdcall MsgProcess(
  70. int num ,// in -error number/level code
  71. WCHAR const * str // in -error string to display
  72. );
  73. virtual void __stdcall StrWrite(int level, WCHAR const * str) const { if (level >= dispLevel) wprintf(L"%s\n", str); };
  74. virtual BOOL LogOpen(
  75. WCHAR const * fileName ,// in -name of file including any path
  76. int mode = 0 ,// in -0=overwrite, 1=append
  77. int level = 0 ,// in -minimum level to log
  78. bool bBeginNew = false // in -begin a new log file
  79. );
  80. virtual void LogClose() { if ( logFile ) fclose(logFile); };
  81. virtual void LogWrite(WCHAR const * msg);
  82. void LevelSet(int displevel=0, int loglevel=-1, int beeplevel=2)
  83. { dispLevel = displevel; logLevel = loglevel; beepLevel = beeplevel; };
  84. void LevelDispSet(int displevel=0)
  85. { dispLevel = displevel; };
  86. void LevelLogSet(int loglevel=-1)
  87. { logLevel = loglevel; };
  88. void LevelBeepSet(int beeplevel=-1)
  89. { beepLevel = beeplevel; };
  90. DWORD MaxError() const { return maxError; };
  91. DWORD LastError() const { return lastError; };
  92. int GetMaxSeverityLevel () { return maxError / 10000; }
  93. virtual WCHAR * ErrorCodeToText(
  94. DWORD code ,// in -message code
  95. DWORD lenMsg ,// in -length of message text area
  96. WCHAR * msg // out-returned message text
  97. );
  98. };
  99. extern TError & errCommon;
  100. #endif // MCSINC_Err_hpp
  101. // Err.hpp - end of file