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.

175 lines
3.0 KiB

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