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.

149 lines
2.8 KiB

  1. ////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2000, Microsoft Corporation.
  4. //
  5. // All rights reserved.
  6. //
  7. // Module Name:
  8. //
  9. // _log.h
  10. //
  11. // Abstract:
  12. //
  13. // declaration of log module and class
  14. //
  15. // History:
  16. //
  17. // initial a-marius
  18. //
  19. ////////////////////////////////////////////////////////////////////////////////////
  20. #ifndef __MY_LOG_H__
  21. #define __MY_LOG_H__
  22. #if _MSC_VER > 1000
  23. #pragma once
  24. #endif _MSC_VER > 1000
  25. #ifdef __SUPPORT_LOGGING
  26. ////////////////////////////////////////////////////////////////////////////////////
  27. // abstract base
  28. ////////////////////////////////////////////////////////////////////////////////////
  29. template < class __DUMMY >
  30. class ATL_NO_VTABLE MyLog
  31. {
  32. DECLARE_NO_COPY ( MyLog );
  33. public:
  34. MyLog ( )
  35. {
  36. }
  37. ~MyLog ( )
  38. {
  39. }
  40. HRESULT Log ( LPCWSTR wszName, DWORD dwResult );
  41. HRESULT Log ( LPCWSTR wszName );
  42. };
  43. template < class __DUMMY >
  44. HRESULT MyLog < __DUMMY > :: Log ( LPCWSTR wszName, DWORD dwResult )
  45. {
  46. HRESULT hr = E_OUTOFMEMORY;
  47. WCHAR* psz = NULL;
  48. if ( !wszName )
  49. {
  50. hr = E_INVALIDARG;
  51. }
  52. else
  53. {
  54. try
  55. {
  56. DWORD cchSize = lstrlenW ( wszName ) + 1 + 2 + 8 + 1 + 1;
  57. if ( ( psz = new WCHAR [ cchSize ] ) != NULL )
  58. {
  59. if ( SUCCEEDED ( hr = StringCchPrintfW ( psz, cchSize, L"%s %08x", wszName, dwResult ) ) )
  60. {
  61. hr = Log ( psz );
  62. }
  63. }
  64. }
  65. catch ( ... )
  66. {
  67. hr = E_UNEXPECTED;
  68. }
  69. if ( psz )
  70. {
  71. delete [] psz;
  72. psz = NULL;
  73. }
  74. }
  75. return hr;
  76. }
  77. template < class __DUMMY >
  78. HRESULT MyLog < __DUMMY > :: Log ( LPCWSTR wszName )
  79. {
  80. HRESULT hr = E_OUTOFMEMORY;
  81. if ( !wszName )
  82. {
  83. hr = E_INVALIDARG;
  84. }
  85. else
  86. {
  87. DWORD dwThreadId = 0L;
  88. SYSTEMTIME systime;
  89. dwThreadId = ::GetCurrentThreadId ();
  90. ::GetSystemTime ( &systime );
  91. WCHAR* psz = NULL;
  92. try
  93. {
  94. DWORD cchSize = lstrlenW ( wszName ) + 1 + 2 + 8 + 1 + 2 + 3 + 2 + 3 + 2 + 3 + 2 + 3 + 1 + 1;
  95. if ( ( psz = new WCHAR [ cchSize ] ) != NULL )
  96. {
  97. if ( SUCCEEDED ( hr = StringCchPrintfW ( psz, cchSize, L"%s %08x %02d:%02d:%02d:%02d\n", wszName, dwThreadId, systime.wHour, systime.wMinute, systime.wSecond, systime.wMilliseconds ) ) )
  98. {
  99. OutputDebugString ( psz );
  100. hr = S_OK;
  101. }
  102. }
  103. }
  104. catch ( ... )
  105. {
  106. hr = E_UNEXPECTED;
  107. }
  108. if ( psz )
  109. {
  110. delete [] psz;
  111. psz = NULL;
  112. }
  113. }
  114. return hr;
  115. }
  116. __declspec ( selectany ) MyLog< void > log;
  117. // macros
  118. #define AdapterLogMessage0(lpszMessage) log.Log ( lpszMessage )
  119. #define AdapterLogMessage1(lpszMessage, dwResult) log.Log ( lpszMessage, dwResult )
  120. #else __SUPPORT_LOGGING
  121. // macros
  122. #define AdapterLogMessage0(lpszMessage)
  123. #define AdapterLogMessage1(lpszMessage, dwResult)
  124. #endif __SUPPORT_LOGGING
  125. #endif __MY_LOG_H__