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.

133 lines
3.1 KiB

  1. //
  2. // MODULE: LogString.cpp
  3. //
  4. // PURPOSE: implementation of the CLogString class.
  5. //
  6. // PROJECT: Generic Troubleshooter DLL for Microsoft AnswerPoint
  7. //
  8. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  9. //
  10. // AUTHOR: Roman Mach, Joe Mabel
  11. //
  12. // ORIGINAL DATE: 7/24/1998
  13. //
  14. // NOTES:
  15. // 1. For public "Add" methods of this class: unless otherwise noted, if called more than once,
  16. // only last call is significant
  17. //
  18. // Version Date By Comments
  19. //--------------------------------------------------------------------
  20. // V3.0 7-24-98 JM Major revision, deprecate IDH.
  21. //
  22. #include "stdafx.h"
  23. #include "LogString.h"
  24. #include "SafeTime.h"
  25. //////////////////////////////////////////////////////////////////////
  26. // Construction/Destruction
  27. //////////////////////////////////////////////////////////////////////
  28. CLogString::CLogString()
  29. {
  30. time( &m_timeStart );
  31. m_bLoggedError = false;
  32. m_dwError = 0;
  33. m_dwSubError = 0;
  34. }
  35. CLogString::~CLogString()
  36. {
  37. }
  38. CString CLogString::GetStr() const
  39. {
  40. CString str;
  41. CString strDuration;
  42. GetDurationString(strDuration);
  43. GetStartTimeString(str);
  44. str += _T(", ");
  45. str += m_strCookie;
  46. str += m_strTopic;
  47. str += strDuration;
  48. str += _T(", ");
  49. str += m_strStates;
  50. str += m_strCurNode;
  51. if (m_bLoggedError)
  52. {
  53. CString strError;
  54. strError.Format(_T(", Err=%ld(%ld)"), m_dwError, m_dwSubError);
  55. str +=strError;
  56. }
  57. str += _T("\n");
  58. return str;
  59. }
  60. void CLogString::AddCookie(LPCTSTR szCookie)
  61. {
  62. m_strCookie = szCookie;
  63. }
  64. // INPUT szTopic: troubleshooter topic (a.k.a. troubleshooter symbolic name)
  65. void CLogString::AddTopic(LPCTSTR szTopic)
  66. {
  67. m_strTopic.Format(_T(" %s,"), szTopic);
  68. }
  69. // Must be called repeatedly for successive nodes.
  70. // If you want to display nodes in a particular order, this must be called in that order.
  71. void CLogString::AddNode(NID nid, IST ist)
  72. {
  73. CString str;
  74. str.Format(_T("[%d:%d], "), nid, ist);
  75. m_strStates += str;
  76. }
  77. // Add current node (no state because we are currently visiting it)
  78. void CLogString::AddCurrentNode(NID nid)
  79. {
  80. m_strCurNode.Format(_T("Page=%d"), nid);
  81. }
  82. // Only logs an error if dwError != 0
  83. // Can call with dwError == 0 to clear previous error
  84. void CLogString::AddError(DWORD dwError/* =0 */, DWORD dwSubError/* =0 */)
  85. {
  86. m_bLoggedError = dwError ? true :false;
  87. if (m_bLoggedError)
  88. {
  89. m_dwError = dwError;
  90. m_dwSubError = dwSubError;
  91. }
  92. }
  93. // OUTPUT str contains start date/time in form used in log.
  94. void CLogString::GetStartTimeString(CString& str) const
  95. {
  96. TCHAR buf[100]; // plenty big for date/time string
  97. {
  98. // minimize how long we use CSafeTime, because it means holding a mutex.
  99. CSafeTime safe(m_timeStart);
  100. _tcscpy(buf, _tasctime(&(safe.LocalTime())));
  101. }
  102. if (_tcslen(buf))
  103. buf[_tcslen(buf)-1] = _T('\0');// remove cr
  104. str = buf;
  105. }
  106. // OUTPUT str contains form used in log of duration in seconds since m_timeStart.
  107. void CLogString::GetDurationString(CString& str) const
  108. {
  109. time_t timeNow;
  110. time( &timeNow );
  111. str.Format(_T(" Time=%02ds"), timeNow - m_timeStart);
  112. }