]> jfr.im git - irc/quakenet/newserv.git/blame - chanserv/chanservlog.c
Initial Import
[irc/quakenet/newserv.git] / chanserv / chanservlog.c
CommitLineData
c86edd1d
Q
1#include <sys/types.h>
2#include <sys/stat.h>
3#include <fcntl.h>
4#include <unistd.h>
5#include <stdarg.h>
6#include <stdio.h>
7#include "chanserv.h"
8
9int logfd;
10
11void cs_initlog() {
12 logfd=open("chanservlog.0",O_WRONLY|O_CREAT|O_APPEND,S_IRUSR|S_IWUSR);
13}
14
15void cs_closelog() {
16 if (logfd>=0)
17 close(logfd);
18}
19
20void cs_log(nick *np, char *event, ... ) {
21 char buf[512];
22 char buf2[1024];
23 char userbuf[512];
24 va_list va;
25 struct tm *tm;
26 time_t now;
27 char timebuf[100];
28 int len;
29
30 if (logfd<0)
31 return;
32
33 va_start(va,event);
34 vsnprintf(buf,512,event,va);
35 va_end(va);
36
37 if (np) {
38 snprintf(userbuf,511,"%s!%s@%s [%s%s]",np->nick,np->ident,np->host->name->content,
39 getreguserfromnick(np)?"auth ":"noauth",getreguserfromnick(np)?getreguserfromnick(np)->username:"");
40 } else {
41 userbuf[0]='\0';
42 }
43
44 now=time(NULL);
45 tm=gmtime(&now);
46 strftime(timebuf,100,"%Y-%m-%d %H:%M:%S",tm);
47 len=snprintf(buf2,1024,"[%s] %s %s\n",timebuf,userbuf,buf);
48 write(logfd, buf2, len);
49}