#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include "DSLog.h"
#include <string.h>
#include <sys/time.h>

void DSLog(const char *format, ...);

void DSLog(const char *format, ...)
{
    va_list arg;
    int done;
    char filename[256];
//    struct timeval tv;
//    struct timezone tz;
//    gettimeofday(&tv, &tz);
//    gettimeofday(&tv, NULL);
//    FILE* pFile = fopen("log.txt", "a");

    va_start(arg, format);
    time_t time_log = time(NULL);
    struct tm* tm_log = localtime(&time_log);

 //   sprintf(filename, "%04d-%02d-%02d.txt", tm_log->tm_year+1900, tm_log->tm_mon + 1, tm_log->tm_mday);

    FILE* pFile = fopen( "log.txt", "a");
//    fprintf(pFile, "%04d-%02d-%02d %02d:%02d:%02d", tm_log->tm_year + 1900, tm_log->tm_mon + 1, tm_log->tm_mday, tm_log->tm_hour, tm_log->tm_min, tm_log->tm_sec);

//    fprintf(pFile, " %02d:%02d:%02d-%ld  <<DASUNG 25.3>>  ", tm_log->tm_hour, tm_log->tm_min, tm_log->tm_sec, tv.tv_usec);
    fprintf(pFile, " %02d:%02d:%02d  <<DASUNG 25.3>>  ", tm_log->tm_hour, tm_log->tm_min, tm_log->tm_sec);

    done = vfprintf(pFile, format, arg);
    va_end(arg);

    fflush(pFile);
    fclose(pFile);
}


