1 #include <stdarg.h>
 2 #include <sys/time.h>
 3 #include <time.h>
 4 #include "log.h"
 5 
 6 void debuglog ( FILE *fh,
 7                 const char *file, const char *function, size_t line,
 8                 const char *fmt, ... )
 9 {
10         struct timeval  tv;
11         va_list         ap;
12         struct tm       tm;
13         time_t          t;
14 
15         gettimeofday(&tv, NULL);
16 
17         t = tv.tv_sec;
18         (void)gmtime_r (&t, &tm);
19         
20         fprintf (fh, "%02d:%02d:%02d.%-8lu %s:%-4zu %s()\n  ",
21                         tm.tm_hour,
22                         tm.tm_min,
23                         tm.tm_sec,
24                         tv.tv_usec,
25                         file, line, function);
26 
27         va_start (ap, fmt);
28 
29         vfprintf (fh, fmt, ap);
30 
31         va_end (ap);
32         
33         fprintf (fh, "\n");
34 }


syntax highlighted by Code2HTML, v. 0.9.1