libventi: add %+T

This commit is contained in:
Russ Cox 2008-12-23 12:32:08 -08:00
parent 7e0b686233
commit ece9d931eb
2 changed files with 7 additions and 22 deletions

View file

@ -162,18 +162,6 @@ vtlogremove(char *name)
qunlock(&vl.lk);
}
static int
timefmt(Fmt *fmt)
{
static uvlong t0;
uvlong t;
if(t0 == 0)
t0 = nsec();
t = nsec()-t0;
return fmtprint(fmt, "T+%d.%04d", (uint)(t/1000000000), (uint)(t%1000000000)/100000);
}
void
vtlogvprint(VtLog *l, char *fmt, va_list arg)
{
@ -185,12 +173,6 @@ vtlogvprint(VtLog *l, char *fmt, va_list arg)
if(l == nil)
return;
if(first){
fmtinstall('T', timefmt);
first = 0;
}
qlock(&l->lk);
c = l->w;
n = c->ep - c->wp;

View file

@ -8,15 +8,18 @@ vttimefmt(Fmt *fmt)
vlong ns;
Tm tm;
if(fmt->flags&FmtLong){
if(fmt->flags&FmtSign){
ns = va_arg(fmt->args, long);
ns *= 1000000000;
} else
ns = nsec();
tm = *localtime(ns/1000000000);
tm = *localtime(ns/1000000000);
if(fmt->flags&FmtLong){
return fmtprint(fmt, "%04d/%02d%02d %02d:%02d:%02d.%03d",
tm.year+1900, tm.mon+1, tm.mday,
tm.hour, tm.min, tm.sec,
(int)(ns%1000000000)/1000000);
}else{
tm = *localtime(time(0));
return fmtprint(fmt, "%04d/%02d%02d %02d:%02d:%02d",
tm.year+1900, tm.mon+1, tm.mday,
tm.hour, tm.min, tm.sec);