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.

101 lines
2.1 KiB

  1. // ========================================================================
  2. // Name: Mohsin Ahmed
  3. // Email: [email protected]
  4. // Date: Tue Dec 03 14:47:46 1996
  5. // File: s:/tftpd/debug.c
  6. // Synopsis: Can output to eventlog, kernel debugger or console.
  7. // ========================================================================
  8. #include <tftpd.h>
  9. int
  10. TftpdPrintLog(
  11. char * format,
  12. ...
  13. )
  14. {
  15. va_list ap;
  16. char message[LEN_DbgPrint];
  17. int message_len, ok;
  18. SYSTEMTIME _st;
  19. GetLocalTime(&_st);
  20. va_start( ap, format );
  21. message_len = vsprintf( message, format, ap );
  22. va_end( ap );
  23. assert( message_len < LEN_DbgPrint );
  24. // ==========================
  25. TftpdLogEvent( EVENTLOG_ERROR_TYPE, message );
  26. if( LogFile ){
  27. fprintf(LogFile,"%2d-%02d: %02d:%02d:%02d ",_st.wMonth,_st.wDay,_st.wHour,_st.wMinute,_st.wSecond);
  28. fprintf( LogFile, message );
  29. fflush( LogFile );
  30. }
  31. #if DBG
  32. if( ! LogFile && ! LoggingEvent ){
  33. OutputDebugString( message );
  34. }
  35. #endif
  36. return message_len;
  37. }
  38. // ========================================================================
  39. // Global: LoggingEvent,
  40. void
  41. TftpdLogEvent( WORD logtype, char message[] )
  42. {
  43. int ok;
  44. HANDLE HEventLog = NULL;
  45. LPCTSTR lpStrings[] = { message };
  46. if( ! LoggingEvent )
  47. return;
  48. HEventLog = RegisterEventSource( NULL, "tftpd" );
  49. if( ! HEventLog ){
  50. LoggingEvent = FALSE;
  51. return;
  52. }
  53. ok =
  54. ReportEvent(
  55. HEventLog,
  56. logtype,
  57. 0, // event category
  58. 0, // dwEventID
  59. NULL, // PSID user security id.
  60. 1, // WORD wNumStrings,
  61. 0, // DWORD dwDataSize.
  62. lpStrings, // LPCTSTR * lpStrings,
  63. NULL // LPVOID lpRawData
  64. );
  65. if( ! ok ){
  66. LoggingEvent = FALSE;
  67. return;
  68. }
  69. ok = DeregisterEventSource(HEventLog);
  70. if( ! ok ){
  71. LoggingEvent = FALSE;
  72. return;
  73. }
  74. return;
  75. }
  76. // ========================================================================