Source code of Windows XP (NT5)
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.

167 lines
3.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: debug.c
  7. //
  8. // Contents: Debugging support functions
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // Note: This file is not compiled for retail builds
  15. //
  16. // History: 4-29-93 RichardW Created.
  17. //
  18. //----------------------------------------------------------------------------
  19. //
  20. // For ease of debugging the SPMgr, all the debug support functions have
  21. // been stuck here. Basically, we read info from win.ini, since that allows
  22. // us to configure the debug level via a text file (and DOS, for example).
  23. //
  24. // Format is:
  25. //
  26. // win.ini
  27. //
  28. // [SPMgr]
  29. // DebugFlags=<Flag>[<,Flag>]*
  30. // Package=<int>
  31. // BreakFlags=<BreakFlag>[<,BreakFlags>]*
  32. //
  33. // WHERE:
  34. // Flag is one of the following:
  35. // Error, Warning, Trace, Verbose, BreakOnError, Helpers,
  36. // RefMon, Locator, WAPI, Init, Audit, Db, Lsa
  37. //
  38. // Package is the name of the dll implementing the package, e.g.
  39. // NTLM=3
  40. //
  41. // BreakFlags will cause SPMgr to break, if BreakOnError is set in
  42. // DebugFlags:
  43. // InitBegin, InitEnd, Connect, Exception, Problem, Load
  44. //
  45. //
  46. #include "testgina.h"
  47. #include <stdio.h>
  48. #include <wchar.h>
  49. FILE * LogFile;
  50. // Debugging support functions.
  51. // These two functions do not exist in Non-Debug builds. They are wrappers
  52. // to the commnot functions (maybe I should get rid of that as well...)
  53. // that echo the message to a log file.
  54. //+---------------------------------------------------------------------------
  55. //
  56. // Function: LogEvent
  57. //
  58. // Synopsis: Logs an event to the console and, optionally, a file.
  59. //
  60. // Effects:
  61. //
  62. // Arguments: [Mask] --
  63. // [Format] --
  64. // [Format] --
  65. //
  66. // Requires:
  67. //
  68. // Returns:
  69. //
  70. // Signals:
  71. //
  72. // Modifies:
  73. //
  74. // Algorithm:
  75. //
  76. // History: 4-29-93 RichardW Created
  77. //
  78. // Notes:
  79. //
  80. //----------------------------------------------------------------------------
  81. void
  82. LogEvent( long Mask,
  83. const char * Format,
  84. ...)
  85. {
  86. va_list ArgList;
  87. int Level = 0;
  88. int PrefixSize = 0;
  89. char szOutString[256];
  90. long OriginalMask = Mask;
  91. if (1)
  92. {
  93. //
  94. // Make the prefix first: "Process.Thread> GINA-XXX"
  95. //
  96. PrefixSize = sprintf(szOutString, "%d.%d> %s: ",
  97. GetCurrentProcessId(), GetCurrentThreadId(), "TestGINA");
  98. va_start(ArgList, Format);
  99. if (_vsnprintf(&szOutString[PrefixSize], sizeof(szOutString) - PrefixSize,
  100. Format, ArgList) < 0)
  101. {
  102. //
  103. // Less than zero indicates that the string could not be
  104. // fitted into the buffer. Output a special message indicating
  105. // that:
  106. //
  107. OutputDebugStringA("GINA!LogEvent: Could not pack string into 256 bytes\n");
  108. }
  109. else
  110. {
  111. OutputDebugStringA(szOutString);
  112. }
  113. if (LogFile)
  114. {
  115. SYSTEMTIME stTime;
  116. FILETIME ftTime;
  117. FILETIME localtime;
  118. NtQuerySystemTime((PLARGE_INTEGER) &ftTime);
  119. FileTimeToLocalFileTime(&ftTime, &localtime);
  120. FileTimeToSystemTime(&localtime, &stTime);
  121. fprintf(LogFile, "%02d:%02d:%02d.%03d: %s\n",
  122. stTime.wHour, stTime.wMinute, stTime.wSecond,
  123. stTime.wMilliseconds, szOutString);
  124. fflush(LogFile);
  125. }
  126. }
  127. }
  128. void
  129. OpenLogFile(LPSTR pszLogFile)
  130. {
  131. LogFile = fopen(pszLogFile, "a");
  132. if (!LogFile)
  133. {
  134. OutputDebugStringA("GINA: Could not open logfile for append");
  135. OutputDebugStringA(pszLogFile);
  136. }
  137. LogEvent(0, "Log File Begins\n");
  138. }