Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. static void write_to_log(const char *fmt, ...){
  2.     va_list lst;
  3.     char line[2048];
  4.     va_start(lst, fmt);
  5.  
  6.     vsnprintf(line,sizeof (line), fmt, lst);
  7.     va_end(lst);
  8.  
  9.  
  10.     FILE *fp  = NULL;
  11.  
  12.     fp = fopen(LOG_FILE, "a");
  13.  
  14.     if(fp == NULL){
  15.         DEBUG_LOG("write_to_log(): failed to create a new log file..");
  16.         return;
  17.     }
  18.  
  19. #if defined(__linux__) || defined(__gnu_linux__)
  20.     time_t stime;
  21.     struct tm *ntime;
  22.  
  23.     time(&stime);
  24.     ntime = gmtime(&stime);
  25.     fprintf(fp, "[%d:%d:%d] LOG: %s", ntime->tm_hour, ntime->tm_min, ntime->tm_sec, line);
  26.  
  27. #elif defined(__WIN32) || (__WIN32__)
  28.  
  29.     #include <windows.h>
  30.     SYSTEMTIME tm;
  31.     GetLocalTime(&tm);
  32.     fprintf(fp, "[%d:%d:%d] LOG: %s", tm->wHour, tm->wMinute, tm->wSecond , line);
  33. #else
  34.     fprintf(fp, "LOG: %s", line);
  35. #endif
  36.  
  37.     fclose(fp);
  38.  
  39.  
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement