hope this helps,
Code:
void logStatus(char *logMsg,...)
{
char info[200];
char eventTime[200];
va_list alist;
time_t logtime;
struct tm *now = NULL;
memset(info, '\0', 200);
memset(eventTime, '\0', 200);
va_start(alist, logMsg);
vsprintf(info, logMsg, alist);
va_end(alist);
time(&logtime);
now=localtime(&logtime);
fprintf(<your_logfile_pointer>, "%04d-%02d-%02d %02d:%02d:%02d %s\n",
1900 + now->tm_year, now->tm_mon + 1, now->tm_mday,
now->tm_hour, now->tm_min, now->tm_sec, info);
}
any part of the code to log a message in to the log file
can make a call to this function
log file would have the appropriate message with time stamp
the log file can be opened , logged with message and closed
upon each time a message can is logged
else can be opened only once and the file pointer can be made available as a global pointer