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.

118 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 ( - __LINE__) // Testing
  23. #define ErrI (00000 + __LINE__) // Information
  24. #define ErrW (10000 + __LINE__) // Warning
  25. #define ErrE (20000 + __LINE__) // Error
  26. #define ErrS (30000 + __LINE__) // Severe error
  27. #define ErrV (40000 + __LINE__) // Very sever error
  28. #define ErrU (50000 + __LINE__) // Unrecoverable error
  29. #define ErrX (60000 + __LINE__) // 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 { wprintf(L"%ls\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. );
  79. virtual void LogClose() { if ( logFile ) fclose(logFile); };
  80. virtual void LogWrite(WCHAR const * msg);
  81. void LevelSet(int displevel=0, int loglevel=-1, int beeplevel=2)
  82. { dispLevel = displevel; logLevel = loglevel; beepLevel = beeplevel; };
  83. void LevelDispSet(int displevel=0)
  84. { dispLevel = displevel; };
  85. void LevelLogSet(int loglevel=-1)
  86. { logLevel = loglevel; };
  87. void LevelBeepSet(int beeplevel=-1)
  88. { beepLevel = beeplevel; };
  89. DWORD MaxError() const { return maxError; };
  90. DWORD LastError() const { return lastError; };
  91. int GetMaxSeverityLevel () { return maxError / 10000; }
  92. virtual WCHAR * ErrorCodeToText(
  93. DWORD code ,// in -message code
  94. DWORD lenMsg ,// in -length of message text area
  95. WCHAR * msg // out-returned message text
  96. );
  97. };
  98. extern TError & errCommon;
  99. #endif // MCSINC_Err_hpp
  100. // Err.hpp - end of file