Update of /cvsroot/linux-atm/linux-atm/src/lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22328
Modified Files:
Tag: V2_5_0
diag.c
Log Message:
add timestamps when writing to a logfile
Index: diag.c
===================================================================
RCS file: /cvsroot/linux-atm/linux-atm/src/lib/diag.c,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.2
diff -C2 -d -r1.2.2.1 -r1.2.2.2
*** diag.c 1 May 2003 13:23:18 -0000 1.2.2.1
--- diag.c 6 Jan 2005 21:44:11 -0000 1.2.2.2
***************
*** 12,15 ****
--- 12,17 ----
#include <string.h>
#include <syslog.h>
+ #include <signal.h>
+ #include <time.h>
#include "atmd.h"
***************
*** 127,131 ****
--- 129,137 ----
FILE *to;
char buffer[MAX_DIAG_MSG+1];
+ struct timeval tv;
int i;
+ #define DATESTR_LEN 32
+ char datestr[DATESTR_LEN];
+ struct tm tm;
for (walk = components; walk; walk = walk->next)
***************
*** 140,145 ****
}
else {
! if (app_name) fprintf(to,"%s:%s: ",app_name,component);
! else fprintf(to,"%s: ",component);
vfprintf(to,fmt,ap);
fputc('\n',to);
--- 146,157 ----
}
else {
! gettimeofday(&tv,NULL);
! localtime_r((time_t *) &tv.tv_sec, &tm);
! strftime(datestr, DATESTR_LEN, "%b %d %T", &tm);
! if (app_name)
! fprintf(to, "%s.%06lu %s:%s: ",
! datestr, (unsigned long) tv.tv_usec, app_name, component);
! else
! fprintf(to,"%s.%06lu %s: ", datestr, (unsigned long) tv.tv_usec, component);
vfprintf(to,fmt,ap);
fputc('\n',to);
|