]> jfr.im git - irc/quakenet/newserv.git/blob - core/error.c
r657@blue (orig r496): slug | 2006-05-16 00:09:51 +0100
[irc/quakenet/newserv.git] / core / error.c
1 /* error.c */
2
3 #include <stdarg.h>
4 #include <time.h>
5 #include <stdio.h>
6 #include "error.h"
7
8 char *sevtostring(int severity) {
9 switch(severity) {
10 case ERR_DEBUG:
11 return "debug";
12
13 case ERR_INFO:
14 return "info";
15
16 case ERR_WARNING:
17 return "warning";
18
19 case ERR_ERROR:
20 return "error";
21
22 case ERR_FATAL:
23 return "fatal error";
24
25 default:
26 return "unknown error";
27 }
28 }
29
30 void Error(char *source, int severity, char *reason, ... ) {
31 char buf[512];
32 va_list va;
33 struct tm *tm;
34 time_t now;
35 char timebuf[100];
36
37 va_start(va,reason);
38 vsnprintf(buf,512,reason,va);
39 va_end(va);
40
41 if (severity>ERR_DEBUG) {
42 now=time(NULL);
43 tm=gmtime(&now);
44 strftime(timebuf,100,"%Y-%m-%d %H:%M:%S",tm);
45 fprintf(stderr,"[%s] %s(%s): %s\n",timebuf,sevtostring(severity),source,buf);
46 }
47 }