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.

155 lines
2.4 KiB

  1. // Logger.cpp: implementation of the CPersistor class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include <string>
  6. #include <iosfwd>
  7. #include <iostream>
  8. #include <fstream>
  9. #include <ctime>
  10. #include <list>
  11. using namespace std;
  12. #include <malloc.h>
  13. #include <tchar.h>
  14. #include <windows.h>
  15. #ifdef NONNT5
  16. typedef unsigned long ULONG_PTR;
  17. #endif
  18. #include <wmistr.h>
  19. #include <guiddef.h>
  20. #include <initguid.h>
  21. #include <evntrace.h>
  22. #include <WTYPES.H>
  23. #include "t_string.h"
  24. #include "Persistor.h"
  25. #include "Utilities.h"
  26. #include "StructureWrappers.h"
  27. #include "StructureWapperHelpers.h"
  28. #include "Logger.h"
  29. #ifdef _UNICODE
  30. static TCHAR g_tcBeginFile[] = {0xfeff,0x0d, 0x0a};
  31. static TCHAR g_atcNL[] = {0x0d, 0x0a, 0x00};
  32. #endif
  33. CLogger::CLogger(LPCTSTR lpctstrFileName, bool bAppend)
  34. {
  35. #ifdef _UNICODE
  36. m_sFileName = NewLPSTR((LPCWSTR) const_cast<LPTSTR>(lpctstrFileName));
  37. #else
  38. m_sFileName = NewTCHAR(lpctstrFileName);
  39. #endif
  40. m_pPersistor = new CPersistor(m_sFileName, ios::out, false);
  41. m_hr = m_pPersistor -> OpenLog(bAppend);
  42. }
  43. CLogger::~CLogger()
  44. {
  45. free(m_sFileName);
  46. delete m_pPersistor;
  47. }
  48. int CLogger::LogTCHAR(LPCTSTR lpctstrOut)
  49. {
  50. if (FAILED(m_hr))
  51. {
  52. return m_hr;
  53. }
  54. PutALine(m_pPersistor->Stream(), lpctstrOut, -1);
  55. return 0;
  56. }
  57. int CLogger::LogTime(time_t &Time)
  58. {
  59. if (FAILED(m_hr))
  60. {
  61. return m_hr;
  62. }
  63. TCHAR tcArray[26];
  64. LPCTSTR lpctstrTime = t_ctime(&Time);
  65. _tcscpy(tcArray,lpctstrTime);
  66. tcArray[24] = _T('\0');
  67. TCHAR *p = tcArray;
  68. PutALine(m_pPersistor->Stream(), p, -1);
  69. return 0;
  70. }
  71. int CLogger::LogULONG(ULONG ul, bool bHex)
  72. {
  73. if (FAILED(m_hr))
  74. {
  75. return m_hr;
  76. }
  77. if (bHex)
  78. {
  79. PutALine(m_pPersistor->Stream(), _T("0x"), -1);
  80. }
  81. PutAULONGVar(m_pPersistor->Stream(), ul, bHex);
  82. return 0;
  83. }
  84. int CLogger::LogULONG64(ULONG64 ul, bool bHex)
  85. {
  86. if (FAILED(m_hr))
  87. {
  88. return m_hr;
  89. }
  90. if (bHex)
  91. {
  92. PutALine(m_pPersistor->Stream(), _T("0x"), -1);
  93. }
  94. PutAULONG64Var(m_pPersistor->Stream(), ul);
  95. return 0;
  96. }
  97. int CLogger::LogGUID(GUID Guid)
  98. {
  99. if (FAILED(m_hr))
  100. {
  101. return m_hr;
  102. }
  103. GUIDOut(m_pPersistor->Stream(), Guid);
  104. return 0;
  105. }
  106. int CLogger::LogEventTraceProperties(PEVENT_TRACE_PROPERTIES pProps)
  107. {
  108. if (FAILED(m_hr))
  109. {
  110. return m_hr;
  111. }
  112. if (pProps == NULL)
  113. {
  114. PutALine(m_pPersistor->Stream(),_T("_EVENT_TRACE_PROPERTIES Instance NULL\n"),-1);
  115. return 0;
  116. }
  117. CEventTraceProperties Props(pProps);
  118. m_pPersistor->Stream() << Props;
  119. return 0;
  120. }