Advertisement
lelejau

PT2Hook - Logging

Dec 21st, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "Logging.h"
  3.  
  4.  
  5. struct tm *Logging::currentDate;
  6.  
  7. bool Logging::Start()
  8. {
  9.     time_t rawTime;
  10.     auto now = static_cast<DWORD>(time(&rawTime));
  11.     Logging::currentDate = localtime(&rawTime);
  12.  
  13.     char friendlyDate[64] = "";
  14.     _snprintf(friendlyDate, 64, "Date: %02d/%02d/%d  Time: %02d:%02d:%02d",
  15.  
  16.         Logging::currentDate->tm_mday,
  17.         Logging::currentDate->tm_mon + 1,
  18.         Logging::currentDate->tm_year + 1900,
  19.        
  20.         Logging::currentDate->tm_hour,
  21.         Logging::currentDate->tm_min,
  22.         Logging::currentDate->tm_sec);
  23.  
  24.  
  25.     printf("Logging started in: %s\n", friendlyDate);
  26.     return TRUE;
  27.  
  28. }
  29.  
  30. void Logging::UpdateTime()
  31. {
  32.     time_t rawTime;
  33.     auto now = static_cast<DWORD>(time(&rawTime));
  34.  
  35.     Logging::currentDate = localtime(&rawTime);
  36. }
  37.  
  38. void Logging::PrintDebug(const char* szFormat, ...)
  39. {
  40.     va_list arg;
  41.     char firstFormat[512] = "";
  42.     char final[512] = "";
  43.  
  44.  
  45.     va_start(arg, szFormat);
  46.     _vsnprintf_s(firstFormat, 512, 511, szFormat, arg);
  47.     va_end(arg);
  48.    
  49.     Logging::UpdateTime();
  50.     // concatenate the time
  51.     wsprintf(final, "[### DEBUG ###] - %02d:%02d:%02d - %s",
  52.         Logging::currentDate->tm_hour,
  53.         Logging::currentDate->tm_min,
  54.         Logging::currentDate->tm_sec,
  55.         firstFormat);
  56.    
  57.     printf(final);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement