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.

88 lines
5.2 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright � Microsoft Corporation. All rights reserved.
  4. //
  5. // BrodCast.h
  6. //
  7. // Purpose: Logging functions
  8. //
  9. //***************************************************************************
  10. #if _MSC_VER > 1000
  11. #pragma once
  12. #endif
  13. #ifndef BRODCAST_IS_INCLUDED
  14. #define BRODCAST_IS_INCLUDED
  15. #include <time.h>
  16. #include <CRegCls.h>
  17. //#define MAX_STRING_SIZE 4096
  18. class POLARITY ProviderLog;
  19. extern POLARITY ProviderLog captainsLog;
  20. // Needed to add L to the __FILE__
  21. #define __T2(x) L ## x
  22. #define _T2(x) __T2(x)
  23. // macros to make calling easier
  24. // first two versions of LogMessage spots in the file & line number for you
  25. #define LogMessage(pszMessageString) captainsLog.LocalLogMessage(pszMessageString, _T2(__FILE__), __LINE__, ProviderLog::Verbose)
  26. #define LogMessage2(pszMessageString, p1) captainsLog.LocalLogMessage(_T2(__FILE__), __LINE__, ProviderLog::Verbose, pszMessageString, p1)
  27. #define LogMessage3(pszMessageString, p1, p2) captainsLog.LocalLogMessage(_T2(__FILE__), __LINE__, ProviderLog::Verbose, pszMessageString, p1, p2)
  28. #define LogMessage4(pszMessageString, p1, p2, p3) captainsLog.LocalLogMessage(_T2(__FILE__), __LINE__, ProviderLog::Verbose, pszMessageString, p1, p2, p3)
  29. #define LogMessage5(pszMessageString, p1, p2, p3, p4) captainsLog.LocalLogMessage(_T2(__FILE__), __LINE__, ProviderLog::Verbose, pszMessageString, p1, p2, p3, p4)
  30. #define LogMessage6(pszMessageString, p1, p2, p3, p4, p5) captainsLog.LocalLogMessage(_T2(__FILE__), __LINE__, ProviderLog::Verbose, pszMessageString, p1, p2, p3, p4, p5)
  31. #define LogMessage7(pszMessageString, p1, p2, p3, p4, p5, p6) captainsLog.LocalLogMessage(_T2(__FILE__), __LINE__, ProviderLog::Verbose, pszMessageString, p1, p2, p3, p4, p5, p6)
  32. #define LogMessage8(pszMessageString, p1, p2, p3, p4, p5, p6, p7) captainsLog.LocalLogMessage(_T2(__FILE__), __LINE__, ProviderLog::Verbose, pszMessageString, p1, p2, p3, p4, p5, p6, p7)
  33. #define LogErrorMessage(pszMessageString) captainsLog.LocalLogMessage(pszMessageString, _T2(__FILE__), __LINE__, ProviderLog::ErrorsOnly)
  34. #define LogErrorMessage2(pszMessageString, p1) captainsLog.LocalLogMessage(_T2(__FILE__), __LINE__, ProviderLog::ErrorsOnly, pszMessageString, p1)
  35. #define LogErrorMessage3(pszMessageString, p1, p2) captainsLog.LocalLogMessage(_T2(__FILE__), __LINE__, ProviderLog::ErrorsOnly, pszMessageString, p1, p2)
  36. #define LogErrorMessage4(pszMessageString, p1, p2, p3) captainsLog.LocalLogMessage(_T2(__FILE__), __LINE__, ProviderLog::ErrorsOnly, pszMessageString, p1, p2, p3)
  37. #define LogErrorMessage5(pszMessageString, p1, p2, p3, p4) captainsLog.LocalLogMessage(_T2(__FILE__), __LINE__, ProviderLog::ErrorsOnly, pszMessageString, p1, p2, p3, p4)
  38. #define LogErrorMessage6(pszMessageString, p1, p2, p3, p4, p5) captainsLog.LocalLogMessage(_T2(__FILE__), __LINE__, ProviderLog::ErrorsOnly, pszMessageString, p1, p2, p3, p4, p5)
  39. #define LogErrorMessage7(pszMessageString, p1, p2, p3, p4, p5, p6) captainsLog.LocalLogMessage(_T2(__FILE__), __LINE__, ProviderLog::ErrorsOnly, pszMessageString, p1, p2, p3, p4, p5, p6)
  40. #define LogErrorMessage8(pszMessageString, p1, p2, p3, p4, p5, p6, p7) captainsLog.LocalLogMessage(_T2(__FILE__), __LINE__, ProviderLog::ErrorsOnly, pszMessageString, p1, p2, p3, p4, p5, p6, p7)
  41. #define LogMessageEx(pszMessageString, pszFileName, nLineNo) captainsLog.LocalLogMessage(pszMessageString, pszFileName, nLineNo, ProviderLog::Verbose)
  42. #define LogErrorMessageEx(pszMessageString, pszFileName, nLineNo) captainsLog.LocalLogMessage(pszMessageString, pszFileName, nLineNo, ProviderLog::ErrorsOnly)
  43. #define IsVerboseLoggingEnabled() ((BOOL)(ProviderLog::Verbose == captainsLog.IsLoggingOn(NULL)))
  44. #define IsErrorLoggingEnabled() ((BOOL)captainsLog.IsLoggingOn(NULL))
  45. // provide basic logging functionality
  46. // serialize access to the log file, etc.
  47. // intent is that usage is through the macros above
  48. // don't bother instanciating one of these puppies.
  49. class POLARITY ProviderLog : protected CThreadBase
  50. {
  51. public:
  52. enum LogLevel{None, ErrorsOnly, Verbose };
  53. ProviderLog();
  54. ~ProviderLog();
  55. // Broadcast functions
  56. void LocalLogMessage(LPCWSTR pszMessageString, LPCWSTR pszFileName, int lineNo, LogLevel level);
  57. void LocalLogMessage(LPCWSTR pszFileName, int lineNo, LogLevel level, LPCWSTR pszFormatString,...);
  58. // void POLARITY LocalLogMessage(OLECHAR *pwszFormatString,...);
  59. LogLevel IsLoggingOn(CHString* pPath = NULL);
  60. private:
  61. void CheckFileSize(LARGE_INTEGER& nowSize, const CHString &path);
  62. // note - do not use these directly, use the IsLoggingOn method
  63. unsigned __int64 m_lastLookedAtRegistry; // what time we last looked in the registry to see if logging is enabled
  64. LogLevel m_logLevel; // 0 == no logging; 1 == logging; 2 == verbose logging
  65. LARGE_INTEGER m_maxSize; // Maximum size of log file before rollover
  66. CHString m_path; // complete path of log file
  67. static bool m_beenInitted; // catch someone instanciating one of these...
  68. };
  69. #endif