Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void write_to_log(const char *fmt, ...){
- va_list lst;
- char line[2048];
- va_start(lst, fmt);
- vsnprintf(line,sizeof (line), fmt, lst);
- va_end(lst);
- FILE *fp = NULL;
- fp = fopen(LOG_FILE, "a");
- if(fp == NULL){
- DEBUG_LOG("write_to_log(): failed to create a new log file..");
- return;
- }
- #if defined(__linux__) || defined(__gnu_linux__)
- time_t stime;
- struct tm *ntime;
- time(&stime);
- ntime = gmtime(&stime);
- fprintf(fp, "[%d:%d:%d] LOG: %s", ntime->tm_hour, ntime->tm_min, ntime->tm_sec, line);
- #elif defined(__WIN32) || (__WIN32__)
- #include <windows.h>
- SYSTEMTIME tm;
- GetLocalTime(&tm);
- fprintf(fp, "[%d:%d:%d] LOG: %s", tm->wHour, tm->wMinute, tm->wSecond , line);
- #else
- fprintf(fp, "LOG: %s", line);
- #endif
- fclose(fp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement