X-Git-Url: https://git.distorted.org.uk/~mdw/ezmlm/blobdiff_plain/5b62e993b0af39700031c2875d7f6654e6a02850..f8beb284087c279acfb30506f5bb32baa4949b44:/log.c diff --git a/log.c b/log.c index 15e732e..bf3c7a3 100644 --- a/log.c +++ b/log.c @@ -6,14 +6,21 @@ #include "fmt.h" #include "open.h" +/* appends (not crash-proof) a line to "Log". The format is: */ +/* "timestamp event address[ comment]\n". address is free of ' ' */ +/* Unprintable chars are changed to '?'. Comment may have spaces */ + static substdio ss; static char buf[1]; static char num[FMT_ULONG]; static stralloc line = {0}; +static stralloc fn = {0}; -void log(event,addr) +void log(dir,event,addr,comment) +char *dir; char *event; char *addr; +char *comment; { char ch; int fd; @@ -26,9 +33,22 @@ char *addr; if ((ch < 33) || (ch > 126)) ch = '?'; if (!stralloc_append(&line,&ch)) return; } + if (comment && *comment) { + if (!stralloc_cats(&line," ")) return; + while (ch = *comment++) { + if (ch == '\t') + ch = ' '; + else + if ((ch < 32) || (ch > 126)) ch = '?'; + if (!stralloc_append(&line,&ch)) return; + } + } if (!stralloc_cats(&line,"\n")) return; - fd = open_append("Log"); + if (!stralloc_copys(&fn,dir)) return; + if (!stralloc_cats(&fn,"/Log")) return; + if (!stralloc_0(&fn)) return; + fd = open_append(fn.s); if (fd == -1) return; substdio_fdbuf(&ss,write,fd,buf,sizeof(buf)); substdio_putflush(&ss,line.s,line.len);