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.

198 lines
2.8 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 2000
  3. Module Name:
  4. LogT
  5. Abstract:
  6. This module implements the logging capabilities of SCTest,
  7. specifically the part build for both Unicode and ANSI.
  8. Author:
  9. Eric Perlin (ericperl) 07/21/2000
  10. Environment:
  11. Win32
  12. Notes:
  13. ?Notes?
  14. --*/
  15. #ifndef WIN32_LEAN_AND_MEAN
  16. #define WIN32_LEAN_AND_MEAN
  17. #endif
  18. #include <windows.h>
  19. #include <fstream>
  20. #include <algorithm>
  21. #include "TString.h"
  22. #include "Log.h"
  23. extern BOOL g_fVerbose;
  24. extern FILE *g_fpLog;
  25. /*++
  26. LogThisOnly:
  27. Implements logging according to the following matrix:
  28. Console Output:
  29. | Verbose | Not |
  30. -----------------------------
  31. Not Exp.| cerr | cerr |
  32. -----------------------------
  33. Expected| cout | / |
  34. -----------------------------
  35. If a log was specified, everything is logged.
  36. Arguments:
  37. szMsg supplies the content to be logged
  38. fExpected indicates the expected status
  39. Return Value:
  40. None.
  41. Author:
  42. Eric Perlin (ericperl) 05/31/2000
  43. --*/
  44. void LogThisOnly(
  45. IN LPCTSTR szMsg,
  46. IN BOOL fExpected
  47. )
  48. {
  49. LogLock();
  50. if (!fExpected)
  51. {
  52. LogString2FP(stderr, szMsg);
  53. }
  54. else if (g_fVerbose)
  55. {
  56. LogString2FP(stdout, szMsg);
  57. }
  58. if (NULL != g_fpLog)
  59. {
  60. LogString2FP(g_fpLog, szMsg);
  61. }
  62. LogUnlock();
  63. }
  64. /*++
  65. LogString:
  66. Arguments:
  67. szHeader supplies a header
  68. szMsg supplies the content to be logged
  69. Return Value:
  70. None.
  71. Author:
  72. Eric Perlin (ericperl) 07/26/2000
  73. --*/
  74. void LogString(
  75. IN PLOGCONTEXT pLogCtx,
  76. IN LPCTSTR szHeader,
  77. IN LPCTSTR szS
  78. )
  79. {
  80. if (szHeader)
  81. {
  82. LogString(pLogCtx, szHeader);
  83. }
  84. if (NULL == szS)
  85. {
  86. LogString(pLogCtx, _T("<null>"));
  87. }
  88. else if (0 == _tcslen(szS))
  89. {
  90. LogString(pLogCtx, _T("<empty>"));
  91. }
  92. else
  93. {
  94. LogString(pLogCtx, szS);
  95. }
  96. if (szHeader)
  97. {
  98. LogString(pLogCtx, _T("\n"));
  99. }
  100. }
  101. /*++
  102. LogMultiString:
  103. Arguments:
  104. szMS supplies the multi-string to be logged
  105. szHeader supplies a header
  106. Return Value:
  107. None.
  108. Author:
  109. Eric Perlin (ericperl) 07/26/2000
  110. --*/
  111. void LogMultiString(
  112. IN PLOGCONTEXT pLogCtx,
  113. IN LPCTSTR szMS,
  114. IN LPCTSTR szHeader
  115. )
  116. {
  117. if (szHeader)
  118. {
  119. LogString(pLogCtx, szHeader, _T(" "));
  120. }
  121. if (NULL == szMS)
  122. {
  123. LogString(pLogCtx, _T(" <null>"));
  124. if (szHeader)
  125. {
  126. LogString(pLogCtx, _T("\n"));
  127. }
  128. }
  129. else if ( (TCHAR)'\0' == *szMS )
  130. {
  131. LogString(pLogCtx, _T(" <empty>"));
  132. if (szHeader)
  133. {
  134. LogString(pLogCtx, _T("\n"));
  135. }
  136. }
  137. else
  138. {
  139. LPCTSTR sz = szMS;
  140. while ( (TCHAR)'\0' != *sz )
  141. {
  142. // Display the value.
  143. LogString(pLogCtx, _T(" "), sz);
  144. // Advance to the next value.
  145. sz = sz + _tcslen(sz) + 1;
  146. }
  147. }
  148. }