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.

66 lines
1.8 KiB

  1. //
  2. // trace.cpp -- global vars for trace.h
  3. // copyright (c) Microsoft Corp. 1998
  4. //
  5. // this file should be include in stdafx.cpp
  6. #ifdef DEBUG
  7. #include "tstring.h"
  8. #include <ostream>
  9. #include <fstream>
  10. #include "trace.h"
  11. #include <process.h>
  12. DWORD dwTraceLevel = 0; // default to trace_error
  13. tostream* tdbgout;
  14. DWORD dwTraceIndent = 0;
  15. typedef basic_oftstream<TCHAR> tfstream;
  16. void DebugInit(LPCTSTR pszModule) {
  17. if (!pszModule) {
  18. dwTraceLevel = TRACE_ERROR;
  19. tdbgout = new TdbgStream;
  20. return;
  21. }
  22. CRegKey c;
  23. TCHAR szLogFile[MAX_PATH + 1];
  24. szLogFile[0] = 0;
  25. CString keyname(_T("SOFTWARE\\Debug\\"));
  26. keyname += pszModule;
  27. DWORD rc = c.Open(HKEY_LOCAL_MACHINE, keyname, KEY_READ);
  28. if (rc == ERROR_SUCCESS) {
  29. rc = c.QueryValue(dwTraceLevel, _T("Trace"));
  30. if (rc != ERROR_SUCCESS) {
  31. dwTraceLevel = 1;
  32. }
  33. DWORD len = sizeof(szLogFile);
  34. rc = c.QueryValue(szLogFile, _T("LogFile"), &len);
  35. if (rc != ERROR_SUCCESS) {
  36. szLogFile[0] = 0;
  37. }
  38. if(_tcslen(szLogFile)){
  39. TCHAR szPID[MAX_PATH+1];
  40. _itot(_getpid(), szPID, 10);
  41. StringCchCat(szLogFile, sizeof(szLogFile)/sizeof(szLogFile[0]), szPID);
  42. StringCchCat(szLogFile, sizeof(szLogFile)/sizeof(szLogFile[0]), _T(".log"));
  43. }
  44. }
  45. if (!_tcslen(szLogFile)) {
  46. tdbgout = new TdbgStream;
  47. } else {
  48. USES_CONVERSION;
  49. tdbgout = new tfstream(T2CA(szLogFile), std::ios::out);
  50. }
  51. }
  52. void DebugTerm(void) {
  53. dbgDump.flush();
  54. delete tdbgout;
  55. tdbgout = NULL;
  56. }
  57. #endif
  58. // end of file - trace.cpp