#include <sys/stat.h>
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
void df_debug(const char *fmt, ...)
{
va_list args;
FILE *fdb;
struct tm *tstruct;
time_t tsec;
struct stat ST;
if (!access(DEBUG_FLAG_FILE, F_OK))
{
if (stat(DEBUG_MSG_FILE, &ST) == 0)
{
/* 文件大于2M重写,小于追加 */
if (ST.st_size > 2* 1024 * 1024)
fdb = fopen(DEBUG_MSG_FILE, "w");
else
fdb = fopen(DEBUG_MSG_FILE, "a");
}
/* 调试日志文件不存在,重新创建一个 */
else
{
// Some error happen, ie: file not exist or else
fdb = fopen(DEBUG_MSG_FILE, "w+");
}
if (!fdb)
return;
tsec = time(NULL);
tstruct = localtime(&tsec);
fprintf(fdb, "[%02d:%02d:%02d]", tstruct->tm_hour,
tstruct->tm_min, tstruct->tm_sec);
va_start(args, fmt);
vfprintf(fdb, fmt, args);
va_end(args);
fclose(fdb);
}
return;
}