RE: Include miliseconds in logging
"Raul Igrisan" <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <001101c8327c$df0c7c10$8293d052@Ki> |
I did it months ago against 1.4.1 release:
In log.c add
#include <sys/types.h>
#include <sys/time.h>
And modify
static void format(char *buf, int level, const char *place, int e,
const char *fmt, int with_timestamp)
as follows:
variables:
// time_t t;
struct timeval tv;
int millis;
and the first if ()
if (with_timestamp) {
// time(&t);
gettimeofday(&tv, NULL);
#if LOG_TIMESTAMP_LOCALTIME
tm = gw_localtime(tv.tv_sec);
#else
tm = gw_gmtime(tv.tv_sec);
#endif
// tv_usec is in microseconds
millis = tv.tv_usec / 1000;
sprintf(p, "%04d-%02d-%02d %02d:%02d:%02d.%03d ",
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, millis);
p = strchr(p, '\0');
}
> -----Original Message-----
> From: Juan Nin [mailto:[email protected]]
> Sent: 28 November 2007 19:30
> To: [email protected]
> Subject: Include miliseconds in logging
>
> Hi!
>
> Sorry for this stupid question, but my C skills are very poor and I'm
> not being able to do this correctly...
>
> I want to be able to see miliseconds on my logs, something like having
> this in gwlib/log.c
>
>
> sprintf(p, "%04d-%02d-%02d %02d:%02d:%02d (%d)",
> tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
> tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec);
>
>
> where I added a "(%d)" and "tm.tm_usec"
>
> but I'm not sure where I have to modify the tm struct to include tm_usec
> can anyone guide me on where to modifiy this?
>
> thnx in advance,
>
> Juan
>