Leaked source code of windows server 2003
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.

129 lines
5.5 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. #include "TSync.hpp"
  21. extern TCriticalSection csLogError;
  22. // End of header file dependencies
  23. // ErrMsg error level constants
  24. #define ErrT (00000 - __LINE__) // Testing
  25. #define ErrI (00000) // Information
  26. #define ErrW (10000) // Warning
  27. #define ErrE (20000) // Error
  28. #define ErrS (30000) // Severe error
  29. #define ErrV (40000) // Very sever error
  30. #define ErrU (50000) // Unrecoverable error
  31. #define ErrX (60000) // extremely unrecoverable <g>
  32. #define ErrNone (0)
  33. class TError
  34. {
  35. protected:
  36. int level;
  37. int lastError;
  38. int maxError;
  39. int logLevel; // minimum level to log
  40. int dispLevel; // minimum level to display
  41. HANDLE logFile;
  42. int beepLevel;
  43. BOOL bWriteOnCurPos; // write on the current position
  44. TCriticalSection criticalSection; // used to make sure write is atomic
  45. public:
  46. TError(
  47. int displevel = 0,// in -mimimum severity level to display
  48. int loglevel = 0 ,// in -mimimum severity level to log
  49. WCHAR const * filename = L"",// in -file name of log (NULL if none)
  50. int logmode = 0 ,// in -0=replace, 1=append
  51. int beeplevel = 100 // in -min error level for beeping
  52. // Some people dont like the beeps so we turned it off by default.
  53. );
  54. ~TError();
  55. void __cdecl MsgWrite(
  56. int num ,// in -error number/level code
  57. WCHAR const msg[] ,// in -error message to display
  58. ... // in -printf args to msg pattern
  59. );
  60. #ifndef WIN16_VERSION
  61. void __cdecl SysMsgWrite(
  62. int num ,// in -error number/level code
  63. DWORD lastRc ,// in -error return code
  64. WCHAR const msg[] ,// in -error message/pattern to display
  65. ... // in -printf args to msg pattern
  66. );
  67. void __cdecl SysMsgWrite(
  68. int num ,// in -error number/level code
  69. WCHAR const msg[] ,// in -error message/pattern to display
  70. ... // in -printf args to msg pattern
  71. );
  72. #endif
  73. void __stdcall MsgProcess(
  74. int num ,// in -error number/level code
  75. WCHAR const * str // in -error string to display
  76. );
  77. virtual void __stdcall StrWrite(int level, WCHAR const * str) const { if (level >= dispLevel) wprintf(L"%s\n", str); };
  78. virtual BOOL LogOpen(
  79. WCHAR const * fileName ,// in -name of file including any path
  80. int mode = 0 ,// in -0=overwrite, 1=append
  81. int level = 0 ,// in -minimum level to log
  82. bool bBeginNew = false // in -begin a new log file
  83. );
  84. virtual DWORD ExtendSize(
  85. DWORD dwNumOfBytes // number of bytes to extend
  86. );
  87. virtual void SetWriteOnCurrentPosition(BOOL bSet) { bWriteOnCurPos = bSet; }
  88. virtual void LogClose() { if ( logFile != INVALID_HANDLE_VALUE) CloseHandle(logFile); logFile = INVALID_HANDLE_VALUE; };
  89. virtual void LogWrite(WCHAR const * msg);
  90. void LevelSet(int displevel=0, int loglevel=-1, int beeplevel=2)
  91. { dispLevel = displevel; logLevel = loglevel; beepLevel = beeplevel; };
  92. void LevelDispSet(int displevel=0)
  93. { dispLevel = displevel; };
  94. void LevelLogSet(int loglevel=-1)
  95. { logLevel = loglevel; };
  96. void LevelBeepSet(int beeplevel=-1)
  97. { beepLevel = beeplevel; };
  98. DWORD MaxError() const { return maxError; };
  99. DWORD LastError() const { return lastError; };
  100. int GetMaxSeverityLevel () { return maxError / 10000; }
  101. virtual WCHAR * ErrorCodeToText(
  102. DWORD code ,// in -message code
  103. DWORD lenMsg ,// in -length of message text area
  104. WCHAR * msg // out-returned message text
  105. );
  106. };
  107. extern TError & errCommon;
  108. #endif // MCSINC_Err_hpp
  109. // Err.hpp - end of file