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.

120 lines
2.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: log.cxx
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "precomp.h"
  11. #ifdef LOGGING
  12. static HANDLE _hLogFile = INVALID_HANDLE_VALUE;
  13. BOOL Log_Init( VOID )
  14. {
  15. #if 1
  16. _hLogFile = CreateFile(
  17. L"IrXfer.log",
  18. GENERIC_WRITE,
  19. FILE_SHARE_READ,
  20. NULL,
  21. CREATE_ALWAYS, // overwrite any existing file
  22. FILE_ATTRIBUTE_NORMAL,
  23. NULL
  24. );
  25. #endif
  26. if( INVALID_HANDLE_VALUE == _hLogFile )
  27. return FALSE;
  28. Log( SEV_INFO, "**\r\n**\r\n** Infrared File Transfer Log\r\n**\r\n**" );
  29. return TRUE;
  30. }
  31. VOID Log_Close( VOID )
  32. {
  33. if( INVALID_HANDLE_VALUE != _hLogFile )
  34. {
  35. CloseHandle( _hLogFile );
  36. _hLogFile = INVALID_HANDLE_VALUE;
  37. }
  38. }
  39. VOID Log( DWORD dwSev, LPSTR lpsz )
  40. {
  41. DWORD dwWritten;
  42. LPSTR lpszPrefix = "??";
  43. #if 1
  44. if( INVALID_HANDLE_VALUE == _hLogFile )
  45. if( !Log_Init() )
  46. return;
  47. switch( dwSev )
  48. {
  49. case SEV_INFO: lpszPrefix = ""; break;
  50. case SEV_FUNCTION: lpszPrefix = "Function: "; break;
  51. case SEV_WARNING: lpszPrefix = "WARNING: "; break;
  52. case SEV_ERROR: lpszPrefix = "ERROR! "; break;
  53. }
  54. char Buffer[2000];
  55. sprintf( Buffer,
  56. "[%d] %d %s %s\r\n",
  57. GetTickCount(),
  58. GetCurrentThreadId(),
  59. lpszPrefix,
  60. lpsz
  61. );
  62. WriteFile(
  63. _hLogFile,
  64. Buffer,
  65. lstrlenA(Buffer),
  66. &dwWritten,
  67. NULL
  68. );
  69. #else
  70. char threadId[20];
  71. sprintf(threadId, "[%d] ", GetCurrentThreadId() );
  72. printf(threadId);
  73. switch( dwSev )
  74. {
  75. case SEV_INFO: lpszPrefix = ""; break;
  76. case SEV_FUNCTION: lpszPrefix = "Function: "; break;
  77. case SEV_WARNING: lpszPrefix = "WARNING: "; break;
  78. case SEV_ERROR: lpszPrefix = "ERROR! "; break;
  79. }
  80. printf(lpszPrefix);
  81. printf("%s\n", lpsz);
  82. #endif
  83. }
  84. LPSTR GetSocketMsgSz( INT nSockMsg )
  85. {
  86. switch( nSockMsg )
  87. {
  88. case FD_WRITE: return "FD_WRITE";
  89. case FD_ACCEPT: return "FD_ACCEPT";
  90. case FD_READ: return "FD_READ";
  91. case FD_OOB: return "FD_OOB";
  92. case FD_CLOSE: return "FD_CLOSE";
  93. default: return "UNKNOWN";
  94. }
  95. }
  96. #endif