]> jfr.im git - irc/quakenet/newserv.git/blob - core/error.c
Merge
[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 <stdlib.h>
7 #include "error.h"
8 #include "hooks.h"
9
10 char *sevtostring(int severity) {
11 switch(severity) {
12 case ERR_DEBUG:
13 return "debug";
14
15 case ERR_INFO:
16 return "info";
17
18 case ERR_WARNING:
19 return "warning";
20
21 case ERR_ERROR:
22 return "error";
23
24 case ERR_FATAL:
25 return "fatal error";
26
27 case ERR_STOP:
28 return "terminal error";
29
30 default:
31 return "unknown error";
32 }
33 }
34
35 void Error(char *source, int severity, char *reason, ... ) {
36 char buf[512];
37 va_list va;
38 struct tm *tm;
39 time_t now;
40 char timebuf[100];
41
42 va_start(va,reason);
43 vsnprintf(buf,512,reason,va);
44 va_end(va);
45
46 if (severity>ERR_DEBUG) {
47 now=time(NULL);
48 tm=gmtime(&now);
49 strftime(timebuf,100,"%Y-%m-%d %H:%M:%S",tm);
50 fprintf(stderr,"[%s] %s(%s): %s\n",timebuf,sevtostring(severity),source,buf);
51 }
52
53 if (severity>=ERR_STOP) {
54 fprintf(stderr,"Terminal error occured, exiting...\n");
55 triggerhook(HOOK_CORE_STOPERROR, NULL);
56 exit(0);
57 }
58 }