#include <iostream>
#include <stdio.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "log.h"
using namespace std;
void glog(const char *txt, ...)
{
FILE *fp;
char buf[3072];
char file_name[128];
static int log_num = 0;
va_list args;
va_start(args, txt);
vsprintf(buf, txt, args);
va_end(args);
if ( exists_file("../log") == 0 )
system( "mkdir log" );
sprintf( file_name, "../log/log.txt" );
if ((fp = fopen(file_name, "a")) == NULL)
return;
if ( log_num == 0 )
{
fprintf( fp, "\n\n\n\n\n------------------------\n" ); log_num++;
}
else
log_num++;
fprintf(fp, "%d. %s\n", log_num, buf);
fclose(fp);
}
bool exists_file( char *filen )
{
struct stat fst;
if ( stat( filen, &fst) == -1 )
return false; return true;
}