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.

106 lines
2.2 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 ( INVALID_HANDLE_VALUE == _hLogFile ) {
  44. if( !Log_Init() ) {
  45. return;
  46. }
  47. }
  48. switch( dwSev )
  49. {
  50. case SEV_INFO: lpszPrefix = ""; break;
  51. case SEV_FUNCTION: lpszPrefix = "Function: "; break;
  52. case SEV_WARNING: lpszPrefix = "WARNING: "; break;
  53. case SEV_ERROR: lpszPrefix = "ERROR! "; break;
  54. }
  55. char Buffer[2000];
  56. StringCbPrintfA(
  57. Buffer,
  58. sizeof(Buffer),
  59. "[%d] %d %s %s\r\n",
  60. GetTickCount(),
  61. GetCurrentThreadId(),
  62. lpszPrefix,
  63. lpsz
  64. );
  65. WriteFile(
  66. _hLogFile,
  67. Buffer,
  68. lstrlenA(Buffer),
  69. &dwWritten,
  70. NULL
  71. );
  72. }
  73. LPSTR GetSocketMsgSz( INT nSockMsg )
  74. {
  75. switch( nSockMsg )
  76. {
  77. case FD_WRITE: return "FD_WRITE";
  78. case FD_ACCEPT: return "FD_ACCEPT";
  79. case FD_READ: return "FD_READ";
  80. case FD_OOB: return "FD_OOB";
  81. case FD_CLOSE: return "FD_CLOSE";
  82. default: return "UNKNOWN";
  83. }
  84. }
  85. #endif