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.

147 lines
4.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1997.
  5. //
  6. // File: mylog.hxx
  7. //
  8. // Contents: A class that performs logging operations, optionally using NTLOG
  9. // To emulate ntlog without linking to ntlog.lib or using ntlog.dll
  10. // compile with the NO_NTLOG flag defined.
  11. //
  12. // Classes: CLog
  13. //
  14. // Functions:
  15. //
  16. // Coupling:
  17. //
  18. // Notes:
  19. //
  20. // History: 10-15-1996 ericne Created
  21. //
  22. //----------------------------------------------------------------------------
  23. #define NO_NTLOG
  24. #ifndef _CMYLOG
  25. #define _CMYLOG
  26. #include <ntlog.h>
  27. // This is only if we do not intend on using ntlog.dll
  28. #ifdef NO_NTLOG
  29. // The number of different messages that can be logged. This is used to
  30. // track of the log statistics
  31. const ULONG cMessageLevels = 16;
  32. // Used to determine whether a log message is a test, variation, or neither
  33. const DWORD dwTestTypesMask = ( TLS_VARIATION | TLS_TEST );
  34. // The different message types
  35. const DWORD dwMessageTypesMask = ( TLS_INFO | TLS_SEV1 | TLS_SEV2 |
  36. TLS_ABORT | TLS_WARN | TLS_BLOCK |
  37. TLS_PASS | TLS_SEV3 );
  38. #endif
  39. const size_t MaxLogLineLength = 1024;
  40. // By default, the log will be initialized using dwDefaultStyle as the logging
  41. // style.
  42. const DWORD dwDefaultStyle = ( TLS_INFO | TLS_SEV1 | TLS_SEV2 | TLS_SEV3 |
  43. TLS_WARN | TLS_BLOCK | TLS_PASS | TLS_TEST |
  44. TLS_TESTDEBUG | TLS_VARIATION | TLS_ABORT |
  45. TLS_REFRESH | TLS_SORT | TLS_PROLOG );
  46. // To determine if a particular message exceeds the threshold and should be,
  47. // dwStyle is AND'ed with this mask to ignore the non-useful bits
  48. const DWORD dwThresholdMask = ( TLS_ABORT | TLS_SEV1 | TLS_SEV2 |
  49. TLS_SEV3 | TLS_WARN | TLS_PASS | TLS_INFO );
  50. //+---------------------------------------------------------------------------
  51. //
  52. // Class: CLog ()
  53. //
  54. // Purpose: Log module that can emulate ntlog, or use ntlog based on a
  55. // compile flag
  56. //
  57. // Interface: CLog -- Constructor
  58. // ~CLog -- Destructor
  59. // Enable -- Activates the log object
  60. // Disable -- Disables the log object
  61. // SetThreshold -- Sets a threshold for all logged messages
  62. // InitLog -- Initializes the log
  63. // Log -- Takes a variable number of arguments
  64. // vLog -- Takes a va_list as a parameter
  65. // m_dwThreshold -- Messages that don't exceed this threshold
  66. // are not logged
  67. // m_fEnabled -- TRUE if the the log is enabled
  68. // #ifdef NO_NTLOG
  69. // ReportStats -- Used to report the statistics for this log
  70. // Called from destructor
  71. // m_pLogFile -- FILE* for the log file
  72. // m_dwLogStyle -- Style used to initialize the log
  73. // m_ulNbrMessages -- Keeps track of the log statistics
  74. // m_CriticalSection -- For multi-threaded applications
  75. // #else
  76. // m_hLog -- Handle to the log returned by tlCreateLog
  77. // #endif
  78. //
  79. // History: 1-15-1997 ericne Created
  80. //
  81. // Notes:
  82. //
  83. //----------------------------------------------------------------------------
  84. class CLog
  85. {
  86. public:
  87. CLog();
  88. virtual ~CLog();
  89. virtual void Enable();
  90. virtual void Disable();
  91. virtual void SetThreshold( DWORD );
  92. virtual BOOL InitLog( LPCTSTR, DWORD = dwDefaultStyle );
  93. virtual BOOL Log( DWORD, LPTSTR, int, LPCTSTR, ... );
  94. virtual BOOL vLog( DWORD, LPTSTR, int, LPCTSTR, va_list );
  95. virtual BOOL AddParticipant();
  96. virtual BOOL RemoveParticipant();
  97. virtual void ReportStats( );
  98. protected:
  99. DWORD m_dwThreshold;
  100. BOOL m_fEnabled;
  101. #ifdef NO_NTLOG
  102. FILE* m_pLogFile;
  103. DWORD m_dwLogStyle;
  104. ULONG m_ulNbrMessages[ cMessageLevels ];
  105. CRITICAL_SECTION m_CriticalSection;
  106. #else
  107. HANDLE m_hLog;
  108. #endif
  109. };
  110. #endif