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.

898 lines
22 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1997-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // LogSrc.cpp
  7. //
  8. // Description:
  9. // Logging utilities.
  10. //
  11. // Documentation:
  12. // Spec\Admin\Debugging.ppt
  13. //
  14. // Maintained By:
  15. // Galen Barbee (GalenB) 05-DEC-2000
  16. //
  17. //////////////////////////////////////////////////////////////////////////////
  18. #include <stdio.h>
  19. #include <tchar.h>
  20. #include "Common.h"
  21. //****************************************************************************
  22. //****************************************************************************
  23. //
  24. // Logging Functions
  25. //
  26. // These are in both DEBUG and RETAIL.
  27. //
  28. //****************************************************************************
  29. //****************************************************************************
  30. //
  31. // Constants
  32. //
  33. static const int LOG_OUTPUT_BUFFER_SIZE = 512;
  34. //
  35. // Globals
  36. //
  37. CRITICAL_SECTION * g_pcsLogging = NULL;
  38. HANDLE g_hLogFile = INVALID_HANDLE_VALUE;
  39. //////////////////////////////////////////////////////////////////////////////
  40. //++
  41. //
  42. // HRESULT
  43. // HrLogOpen( void )
  44. //
  45. // Description:
  46. // This function:
  47. // - initializes the log critical section
  48. // - enters the log critical section assuring only one thread is
  49. // writing to the log at a time
  50. // - creates the directory tree to the log file (if needed)
  51. // - initializes the log file by:
  52. // - creating a new log file if one doesn't exist.
  53. // - opens an existing log file (for append)
  54. // - appends a time/date stamp that the log was (re)opened.
  55. //
  56. // Use LogClose() to exit the log critical section.
  57. //
  58. // If there is a failure inside this function, the log critical
  59. // section will be released before returning.
  60. //
  61. // Arguments:
  62. // None.
  63. //
  64. // Return Values:
  65. // S_OK - log critical section held and log open successfully
  66. // Otherwize HRESULT error code.
  67. //
  68. //--
  69. //////////////////////////////////////////////////////////////////////////////
  70. HRESULT
  71. HrLogOpen( void )
  72. {
  73. TCHAR szFilePath[ MAX_PATH ];
  74. TCHAR szModulePath[ MAX_PATH ];
  75. CHAR szBuffer[ LOG_OUTPUT_BUFFER_SIZE ];
  76. DWORD dwWritten;
  77. HANDLE hTemp;
  78. BOOL fReturn;
  79. HRESULT hr;
  80. SYSTEMTIME SystemTime;
  81. //
  82. // Create a critical section to prevent lines from being fragmented.
  83. //
  84. if ( g_pcsLogging == NULL )
  85. {
  86. PCRITICAL_SECTION pNewCritSect =
  87. (PCRITICAL_SECTION) HeapAlloc( GetProcessHeap(), 0, sizeof( CRITICAL_SECTION ) );
  88. if ( pNewCritSect == NULL )
  89. {
  90. DebugMsg( "DEBUG: Out of Memory. Logging disabled." );
  91. hr = E_OUTOFMEMORY;
  92. goto Cleanup;
  93. } // if: creation failed
  94. InitializeCriticalSection( pNewCritSect );
  95. // Make sure we only have one log critical section
  96. InterlockedCompareExchangePointer( (PVOID *) &g_pcsLogging, pNewCritSect, 0 );
  97. if ( g_pcsLogging != pNewCritSect )
  98. {
  99. DebugMsg( "DEBUG: Another thread already created the CS. Deleting this one." );
  100. DeleteCriticalSection( pNewCritSect );
  101. HeapFree( GetProcessHeap(), 0, pNewCritSect );
  102. } // if: already have another critical section
  103. } // if: no critical section created yet
  104. Assert( g_pcsLogging != NULL );
  105. EnterCriticalSection( g_pcsLogging );
  106. //
  107. // Make sure the log file is open
  108. //
  109. if ( g_hLogFile == INVALID_HANDLE_VALUE )
  110. {
  111. DWORD dwLen;
  112. LPTSTR psz;
  113. //
  114. // Create the directory tree
  115. //
  116. // TODO: 12-DEC-2000 DavidP
  117. // Change this to be more generic. This shouldn't be specific
  118. // to clustering.
  119. //
  120. ExpandEnvironmentStrings( TEXT("%windir%\\system32\\LogFiles\\Cluster"), szFilePath, MAX_PATH );
  121. hr = HrCreateDirectoryPath( szFilePath );
  122. if ( FAILED( hr ) )
  123. {
  124. #if defined( DEBUG )
  125. if ( !( g_tfModule & mtfOUTPUTTODISK ) )
  126. {
  127. DebugMsg( "*ERROR* Failed to create directory tree %s", szFilePath );
  128. } // if: not logging to disk
  129. #endif
  130. goto Error;
  131. } // if: failed
  132. //
  133. // Add filename
  134. //
  135. dwLen = GetModuleFileName( g_hInstance, szModulePath, sizeof( szModulePath ) / sizeof( szModulePath[ 0 ] ) );
  136. Assert( dwLen != 0 );
  137. _tcscpy( &szModulePath[ dwLen - 3 ], TEXT("log") );
  138. psz = _tcsrchr( szModulePath, TEXT('\\') );
  139. Assert( psz != NULL );
  140. if ( psz == NULL )
  141. {
  142. hr = E_POINTER;
  143. goto Error;
  144. }
  145. _tcscat( szFilePath, psz );
  146. //
  147. // Create it
  148. //
  149. g_hLogFile = CreateFile( szFilePath,
  150. GENERIC_WRITE,
  151. FILE_SHARE_READ | FILE_SHARE_WRITE,
  152. NULL,
  153. OPEN_ALWAYS,
  154. FILE_FLAG_WRITE_THROUGH,
  155. NULL
  156. );
  157. if ( g_hLogFile == INVALID_HANDLE_VALUE )
  158. {
  159. #if defined( DEBUG )
  160. if ( !( g_tfModule & mtfOUTPUTTODISK ) )
  161. {
  162. DebugMsg( "*ERROR* Failed to create log at %s", szFilePath );
  163. } // if: not logging to disk
  164. #endif
  165. hr = THR( HRESULT_FROM_WIN32( GetLastError() ) );
  166. goto Error;
  167. } // if: failed
  168. // Seek to the end
  169. SetFilePointer( g_hLogFile, 0, NULL, FILE_END );
  170. //
  171. // Write the time/date the log was (re)openned.
  172. //
  173. GetLocalTime( &SystemTime );
  174. _snprintf( szBuffer,
  175. sizeof( szBuffer ),
  176. "*" ASZ_NEWLINE
  177. "* %04u-%02u-%02u %02u:%02u:%02u.%03u" ASZ_NEWLINE
  178. "*" ASZ_NEWLINE,
  179. SystemTime.wYear,
  180. SystemTime.wMonth,
  181. SystemTime.wDay,
  182. SystemTime.wHour,
  183. SystemTime.wMinute,
  184. SystemTime.wSecond,
  185. SystemTime.wMilliseconds
  186. );
  187. fReturn = WriteFile( g_hLogFile, szBuffer, strlen(szBuffer), &dwWritten, NULL );
  188. if ( ! fReturn )
  189. {
  190. hr = THR( HRESULT_FROM_WIN32( GetLastError() ) );
  191. goto Error;
  192. } // if: failed
  193. DebugMsg( "DEBUG: Created log at %s", szFilePath );
  194. } // if: file not already openned
  195. hr = S_OK;
  196. Cleanup:
  197. return hr;
  198. Error:
  199. DebugMsg( "LogOpen: Failed hr = 0x%08x", hr );
  200. if ( g_hLogFile != INVALID_HANDLE_VALUE )
  201. {
  202. CloseHandle( g_hLogFile );
  203. g_hLogFile = INVALID_HANDLE_VALUE;
  204. } // if: handle was open
  205. LeaveCriticalSection( g_pcsLogging );
  206. goto Cleanup;
  207. } //*** HrLogOpen()
  208. //////////////////////////////////////////////////////////////////////////////
  209. //++
  210. //
  211. // HRESULT
  212. // HrLogRelease( void )
  213. //
  214. // Description:
  215. // This actually just leaves the log critical section.
  216. //
  217. // Arguments:
  218. // None.
  219. //
  220. // Return Values:
  221. // S_OK always.
  222. //
  223. //--
  224. //////////////////////////////////////////////////////////////////////////////
  225. HRESULT
  226. HrLogRelease( void )
  227. {
  228. Assert( g_pcsLogging != NULL );
  229. LeaveCriticalSection( g_pcsLogging );
  230. return S_OK;
  231. } //*** HrLogRelease()
  232. //////////////////////////////////////////////////////////////////////////////
  233. //++
  234. //
  235. // HRESULT
  236. // HrLogClose( void )
  237. //
  238. // Description:
  239. // Close the file. This function expects the critical section to have
  240. // already been released.
  241. //
  242. // Arguments:
  243. // None.
  244. //
  245. // Return Values:
  246. // S_OK always.
  247. //
  248. //--
  249. //////////////////////////////////////////////////////////////////////////////
  250. HRESULT
  251. HrLogClose( void )
  252. {
  253. TraceFunc( "" );
  254. HRESULT hr = S_OK;
  255. if ( g_hLogFile != INVALID_HANDLE_VALUE )
  256. {
  257. CloseHandle( g_hLogFile );
  258. g_hLogFile = INVALID_HANDLE_VALUE;
  259. } // if: handle was open
  260. return hr;
  261. } //*** HrLogClose()
  262. //////////////////////////////////////////////////////////////////////////////
  263. //++
  264. //
  265. // ASCII
  266. //
  267. // void
  268. // LogMsgNoNewline(
  269. // LPCSTR pszFormat,
  270. // ...
  271. // )
  272. //
  273. // Description:
  274. // Logs a message to the log file without adding a newline.
  275. //
  276. // Arguments:
  277. // pszFormat - A printf format string to be printed.
  278. // ,,, - Arguments for the printf string.
  279. //
  280. // Return Values:
  281. // None.
  282. //
  283. //--
  284. //////////////////////////////////////////////////////////////////////////////
  285. void
  286. __cdecl
  287. LogMsgNoNewline(
  288. LPCSTR pszFormat,
  289. ...
  290. )
  291. {
  292. va_list valist;
  293. CHAR szBuf[ LOG_OUTPUT_BUFFER_SIZE ];
  294. DWORD dwWritten;
  295. HRESULT hr;
  296. #ifdef UNICODE
  297. WCHAR szFormat[ LOG_OUTPUT_BUFFER_SIZE ];
  298. WCHAR szTmpBuf[ LOG_OUTPUT_BUFFER_SIZE ];
  299. mbstowcs( szFormat, pszFormat, strlen( pszFormat ) + 1 );
  300. va_start( valist, pszFormat );
  301. wvsprintf( szTmpBuf, szFormat, valist );
  302. va_end( valist );
  303. dwWritten = wcstombs( szBuf, szTmpBuf, wcslen( szTmpBuf ) + 1 );
  304. if ( dwWritten == - 1 )
  305. {
  306. dwWritten = strlen( szBuf );
  307. } // if: bad character found
  308. #else
  309. va_start( valist, pszFormat );
  310. dwWritten = wvsprintf( szBuf, pszFormat, valist );
  311. va_end( valist );
  312. #endif // UNICODE
  313. hr = HrLogOpen();
  314. if ( hr != S_OK )
  315. {
  316. return;
  317. } // if: failed
  318. // LogDateTime();
  319. WriteFile( g_hLogFile, szBuf, dwWritten, &dwWritten, NULL );
  320. HrLogRelease();
  321. } //*** LogMsgNoNewline() ASCII
  322. //////////////////////////////////////////////////////////////////////////////
  323. //++
  324. //
  325. // UNICODE
  326. //
  327. // void
  328. // LogMsgNoNewline(
  329. // LPCWSTR pszFormat,
  330. // ...
  331. // )
  332. //
  333. // Description:
  334. // Logs a message to the log file without adding a newline.
  335. //
  336. // Arguments:
  337. // pszFormat - A printf format string to be printed.
  338. // ,,, - Arguments for the printf string.
  339. //
  340. // Return Values:
  341. // None.
  342. //
  343. //--
  344. //////////////////////////////////////////////////////////////////////////////
  345. void
  346. __cdecl
  347. LogMsgNoNewline(
  348. LPCWSTR pszFormat,
  349. ...
  350. )
  351. {
  352. va_list valist;
  353. CHAR szBuf[ LOG_OUTPUT_BUFFER_SIZE ];
  354. DWORD dwWritten;
  355. HRESULT hr;
  356. #ifdef UNICODE
  357. WCHAR szTmpBuf[ LOG_OUTPUT_BUFFER_SIZE ];
  358. va_start( valist, pszFormat );
  359. wvsprintf( szTmpBuf, pszFormat, valist);
  360. va_end( valist );
  361. dwWritten = wcstombs( szBuf, szTmpBuf, wcslen( szTmpBuf ) + 1 );
  362. if ( dwWritten == -1 )
  363. {
  364. dwWritten = strlen( szBuf );
  365. } // if: bad character found
  366. #else
  367. CHAR szFormat[ LOG_OUTPUT_BUFFER_SIZE ];
  368. wcstombs( szFormat, pszFormat, wcslen( pszFormat ) + 1 );
  369. va_start( valist, pszFormat );
  370. dwWritten = wvsprintf( szBuf, szFormat, valist);
  371. va_end( valist );
  372. #endif // UNICODE
  373. hr = HrLogOpen();
  374. if ( hr != S_OK )
  375. {
  376. return;
  377. } // if: failed
  378. // LogDateTime();
  379. WriteFile( g_hLogFile, szBuf, dwWritten, &dwWritten, NULL );
  380. HrLogRelease();
  381. } //*** LogMsgNoNewline() UNICODE
  382. //////////////////////////////////////////////////////////////////////////////
  383. //++
  384. //
  385. // void
  386. // LogFormatStatusReport(
  387. // CHAR ** ppaszBuffer,
  388. // int iFirstArg,
  389. // ...
  390. // )
  391. //
  392. // Description:
  393. // Formats a status report for writing to the log file.
  394. //
  395. // Arugments:
  396. //
  397. // Return Values:
  398. // None.
  399. //
  400. //--
  401. //////////////////////////////////////////////////////////////////////////////
  402. DWORD
  403. LogFormatStatusReport(
  404. CHAR ** ppaszBuffer,
  405. int iFirstArg,
  406. ...
  407. )
  408. {
  409. va_list valist;
  410. va_start( valist, iFirstArg );
  411. DWORD dw;
  412. dw = FormatMessageA(
  413. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
  414. "%2!02u!/%3!02u!/%4!04u!-%5!02u!:%6!02u!:%7!02u!.%8!02u! - %9!02u!/%10!02u!/%11!04u!-%12!02u!:%13!02u!:%14!02u!.%15!02u! {%16!08X!-%17!04X!-%18!04X!-%19!02X!%20!02X!-%21!02X!%22!02X!%23!02X!%24!02X!%25!02X!%26!02X!}, {%27!08X!-%28!04X!-%29!04X!-%30!02X!%31!02X!-%32!02X!%33!02X!%34!02X!%35!02X!%36!02X!%37!02X!} (%38!2d! / %39!2d! .. %40!2d! ) <%41!ws!> hr=%42!08X! %43!ws! %44!ws!" ASZ_NEWLINE,
  415. 0,
  416. 0,
  417. (LPSTR) ppaszBuffer,
  418. 256,
  419. &valist
  420. );
  421. return dw;
  422. } //*** LogFormatStatusReport()
  423. //////////////////////////////////////////////////////////////////////////////
  424. //++
  425. //
  426. // void
  427. // LogDateTime( void )
  428. //
  429. // Description:
  430. // Adds date/time stamp to the log without a CR. This should be done
  431. // while holding the Logging critical section which is done by calling
  432. // HrLogOpen().
  433. //
  434. // Arguments:
  435. // None.
  436. //
  437. // Return Values:
  438. // None.
  439. //
  440. //--
  441. //////////////////////////////////////////////////////////////////////////////
  442. void
  443. LogDateTime( void )
  444. {
  445. static CHAR szBuffer[ 25 ];
  446. static SYSTEMTIME OldSystemTime = { 0 };
  447. static DWORD dwWritten;
  448. SYSTEMTIME SystemTime;
  449. DWORD dwWhoCares;
  450. int iCmp;
  451. GetLocalTime( &SystemTime );
  452. //
  453. // Avoid expensive printf by comparing times
  454. //
  455. iCmp = memcmp( (PVOID) &SystemTime, (PVOID) &OldSystemTime, sizeof( SYSTEMTIME ) );
  456. if ( iCmp != 0 )
  457. {
  458. dwWritten = _snprintf( szBuffer,
  459. sizeof( szBuffer ),
  460. "%04u-%02u-%02u %02u:%02u:%02u.%03u ",
  461. SystemTime.wYear,
  462. SystemTime.wMonth,
  463. SystemTime.wDay,
  464. SystemTime.wHour,
  465. SystemTime.wMinute,
  466. SystemTime.wSecond,
  467. SystemTime.wMilliseconds
  468. );
  469. Assert( dwWritten < 25 && dwWritten != -1 );
  470. CopyMemory( (PVOID) &OldSystemTime, (PVOID) &SystemTime, sizeof( SYSTEMTIME ) );
  471. } // if: time last different from this time
  472. WriteFile( g_hLogFile, szBuffer, dwWritten, &dwWhoCares, NULL );
  473. } //*** LogDateTime()
  474. //////////////////////////////////////////////////////////////////////////////
  475. //++
  476. //
  477. // void
  478. // LogSystemTime( SYSTEMTIME stSystemTimeIn )
  479. //
  480. // Description:
  481. // Adds date/time stamp to the log without a CR. This should be done
  482. // while holding the Logging critical section which is done by calling
  483. // HrLogOpen().
  484. //
  485. // Arguments:
  486. // None.
  487. //
  488. // Return Values:
  489. // None.
  490. //
  491. //--
  492. //////////////////////////////////////////////////////////////////////////////
  493. void
  494. LogSystemTime( SYSTEMTIME * stSystemTimeIn )
  495. {
  496. static CHAR szBuffer[ 25 ];
  497. DWORD dwWhoCares;
  498. DWORD dwWritten;
  499. dwWritten = _snprintf( szBuffer,
  500. sizeof( szBuffer ),
  501. "%04u-%02u-%02u %02u:%02u:%02u.%03u ",
  502. stSystemTimeIn->wYear,
  503. stSystemTimeIn->wMonth,
  504. stSystemTimeIn->wDay,
  505. stSystemTimeIn->wHour,
  506. stSystemTimeIn->wMinute,
  507. stSystemTimeIn->wSecond,
  508. stSystemTimeIn->wMilliseconds
  509. );
  510. Assert( dwWritten < 25 && dwWritten != -1 );
  511. WriteFile( g_hLogFile, szBuffer, dwWritten, &dwWhoCares, NULL );
  512. } //*** LogSystemTime()
  513. //////////////////////////////////////////////////////////////////////////////
  514. //++
  515. //
  516. // ASCII
  517. //
  518. // void
  519. // LogMsg(
  520. // LPCSTR pszFormat,
  521. // ...
  522. // )
  523. //
  524. // Description:
  525. // Logs a message to the log file and adds a newline.
  526. //
  527. // Arguments:
  528. // pszFormat - A printf format string to be printed.
  529. // ,,, - Arguments for the printf string.
  530. //
  531. // Return Values:
  532. // None.
  533. //
  534. //--
  535. //////////////////////////////////////////////////////////////////////////////
  536. void
  537. __cdecl
  538. LogMsg(
  539. LPCSTR pszFormat,
  540. ...
  541. )
  542. {
  543. va_list valist;
  544. CHAR szBuf[ LOG_OUTPUT_BUFFER_SIZE ];
  545. DWORD dwWritten;
  546. HRESULT hr;
  547. #ifdef UNICODE
  548. WCHAR szFormat[ LOG_OUTPUT_BUFFER_SIZE ];
  549. WCHAR szTmpBuf[ LOG_OUTPUT_BUFFER_SIZE ];
  550. mbstowcs( szFormat, pszFormat, strlen( pszFormat ) + 1 );
  551. va_start( valist, pszFormat );
  552. wvsprintf( szTmpBuf, szFormat, valist);
  553. va_end( valist );
  554. dwWritten = wcstombs( szBuf, szTmpBuf, wcslen( szTmpBuf ) + 1 );
  555. if ( dwWritten == - 1 )
  556. {
  557. dwWritten = strlen( szBuf );
  558. } // if: bad character found
  559. #else
  560. va_start( valist, pszFormat );
  561. dwWritten = wvsprintf( szBuf, pszFormat, valist);
  562. va_end( valist );
  563. #endif // UNICODE
  564. hr = HrLogOpen();
  565. if ( FAILED( hr ) )
  566. goto Cleanup;
  567. LogDateTime();
  568. WriteFile( g_hLogFile, szBuf, dwWritten, &dwWritten, NULL );
  569. WriteFile( g_hLogFile, ASZ_NEWLINE, SIZEOF_ASZ_NEWLINE, &dwWritten, NULL );
  570. HrLogRelease();
  571. Cleanup:
  572. return;
  573. } //*** LogMsg() ASCII
  574. //////////////////////////////////////////////////////////////////////////////
  575. //++
  576. //
  577. // UNICODE
  578. //
  579. // void
  580. // LogMsg(
  581. // LPCWSTR pszFormat,
  582. // ...
  583. // )
  584. //
  585. // Description:
  586. // Logs a message to the log file and adds a newline.
  587. //
  588. // Arguments:
  589. // pszFormat - A printf format string to be printed.
  590. // ,,, - Arguments for the printf string.
  591. //
  592. // Return Values:
  593. // None.
  594. //
  595. //--
  596. //////////////////////////////////////////////////////////////////////////////
  597. void
  598. __cdecl
  599. LogMsg(
  600. LPCWSTR pszFormat,
  601. ...
  602. )
  603. {
  604. va_list valist;
  605. CHAR szBuf[ LOG_OUTPUT_BUFFER_SIZE ];
  606. DWORD dwWritten;
  607. HRESULT hr;
  608. #ifdef UNICODE
  609. WCHAR szTmpBuf[ LOG_OUTPUT_BUFFER_SIZE ];
  610. va_start( valist, pszFormat );
  611. wvsprintf( szTmpBuf, pszFormat, valist);
  612. va_end( valist );
  613. dwWritten = wcstombs( szBuf, szTmpBuf, wcslen( szTmpBuf ) + 1 );
  614. if ( dwWritten == -1 )
  615. {
  616. dwWritten = strlen( szBuf );
  617. } // if: bad character found
  618. #else
  619. CHAR szFormat[ LOG_OUTPUT_BUFFER_SIZE ];
  620. wcstombs( szFormat, pszFormat, wcslen( pszFormat ) + 1 );
  621. va_start( valist, pszFormat );
  622. dwWritten = wvsprintf( szBuf, szFormat, valist);
  623. va_end( valist );
  624. #endif // UNICODE
  625. hr = HrLogOpen();
  626. if ( FAILED( hr ) )
  627. goto Cleanup;
  628. LogDateTime();
  629. WriteFile( g_hLogFile, szBuf, dwWritten, &dwWritten, NULL );
  630. WriteFile( g_hLogFile, ASZ_NEWLINE, SIZEOF_ASZ_NEWLINE, &dwWritten, NULL );
  631. HrLogRelease();
  632. Cleanup:
  633. return;
  634. } //*** LogMsg() UNICODE
  635. //////////////////////////////////////////////////////////////////////////////
  636. //++
  637. //
  638. // void
  639. // LogStatusReport(
  640. // SYSTEMTIME * pstTimeIn,
  641. // const WCHAR * pcszNodeNameIn,
  642. // CLSID clsidTaskMajorIn,
  643. // CLSID clsidTaskMinorIn,
  644. // ULONG ulMinIn,
  645. // ULONG ulMaxIn,
  646. // ULONG ulCurrentIn,
  647. // HRESULT hrStatusIn,
  648. // const WCHAR * pcszDescriptionIn,
  649. // const WCHAR * pcszUrlIn
  650. // )
  651. //
  652. // Description:
  653. // Writes a status report to the log file.
  654. //
  655. // Arugments:
  656. //
  657. // Return Values:
  658. // None.
  659. //
  660. //--
  661. //////////////////////////////////////////////////////////////////////////////
  662. void
  663. LogStatusReport(
  664. SYSTEMTIME * pstTimeIn,
  665. const WCHAR * pcszNodeNameIn,
  666. CLSID clsidTaskMajorIn,
  667. CLSID clsidTaskMinorIn,
  668. ULONG ulMinIn,
  669. ULONG ulMaxIn,
  670. ULONG ulCurrentIn,
  671. HRESULT hrStatusIn,
  672. const WCHAR * pcszDescriptionIn,
  673. const WCHAR * pcszUrlIn
  674. )
  675. {
  676. HRESULT hr;
  677. DWORD dw;
  678. DWORD dwWritten;
  679. unsigned long dwArray[50];
  680. CHAR * paszBuffer = NULL;
  681. SYSTEMTIME SystemTime;
  682. SYSTEMTIME SystemTime2;
  683. GetLocalTime( &SystemTime );
  684. if ( pstTimeIn )
  685. {
  686. memcpy( &SystemTime2, pstTimeIn, sizeof( SYSTEMTIME ) );
  687. }
  688. else
  689. {
  690. memset( &SystemTime2, 0, sizeof( SYSTEMTIME) );
  691. }
  692. dw = LogFormatStatusReport(
  693. &paszBuffer,
  694. 0, 0,
  695. // Time One.
  696. SystemTime.wMonth, //1
  697. SystemTime.wDay, //2
  698. SystemTime.wYear, //3
  699. SystemTime.wHour, //4
  700. SystemTime.wMinute, //5
  701. SystemTime.wSecond, //6
  702. SystemTime.wMilliseconds, //7
  703. // Time Two
  704. SystemTime2.wMonth,
  705. SystemTime2.wDay,
  706. SystemTime2.wYear,
  707. SystemTime2.wHour,
  708. SystemTime2.wMinute,
  709. SystemTime2.wSecond,
  710. SystemTime2.wMilliseconds,
  711. // GUID One
  712. clsidTaskMajorIn.Data1,
  713. clsidTaskMajorIn.Data2,
  714. clsidTaskMajorIn.Data3,
  715. clsidTaskMajorIn.Data4[0],
  716. clsidTaskMajorIn.Data4[1],
  717. clsidTaskMajorIn.Data4[2],
  718. clsidTaskMajorIn.Data4[3],
  719. clsidTaskMajorIn.Data4[4],
  720. clsidTaskMajorIn.Data4[5],
  721. clsidTaskMajorIn.Data4[6],
  722. clsidTaskMajorIn.Data4[7],
  723. // GUID Two
  724. clsidTaskMinorIn.Data1,
  725. clsidTaskMinorIn.Data2,
  726. clsidTaskMinorIn.Data3,
  727. clsidTaskMinorIn.Data4[0],
  728. clsidTaskMinorIn.Data4[1],
  729. clsidTaskMinorIn.Data4[2],
  730. clsidTaskMinorIn.Data4[3],
  731. clsidTaskMinorIn.Data4[4],
  732. clsidTaskMinorIn.Data4[5],
  733. clsidTaskMinorIn.Data4[6],
  734. clsidTaskMinorIn.Data4[7],
  735. // Other...
  736. ulCurrentIn,
  737. ulMinIn,
  738. ulMaxIn,
  739. pcszNodeNameIn,
  740. hrStatusIn,
  741. pcszDescriptionIn,
  742. pcszUrlIn,
  743. 0,
  744. 0
  745. );
  746. // Open the log file.
  747. hr = HrLogOpen();
  748. if ( hr != S_OK )
  749. {
  750. return;
  751. } // if: failed
  752. // Write the initial output.
  753. WriteFile( g_hLogFile, paszBuffer, dw, &dwWritten, NULL );
  754. HrLogRelease();
  755. LocalFree( paszBuffer );
  756. } //*** LogStatusReport
  757. //////////////////////////////////////////////////////////////////////////////
  758. //++
  759. //
  760. // void
  761. // LogTerminateProcess( void )
  762. //
  763. // Description:
  764. // Cleans up anything the logging routines may have created or
  765. // initialized. Typical called from the TraceTerminateProcess() macro.
  766. //
  767. // Arugments:
  768. // None.
  769. //
  770. // Return Values:
  771. // None.
  772. //
  773. //--
  774. //////////////////////////////////////////////////////////////////////////////
  775. void
  776. LogTerminateProcess( void )
  777. {
  778. } //*** LogTerminateProcess()