]> jfr.im git - irc/quakenet/newserv.git/blobdiff - core/error.c
merge
[irc/quakenet/newserv.git] / core / error.c
index a7d0d9955996883ec042f82371103b9d358c247d..895e786c7b17fdce756b702f6013ae0a29cbc29e 100644 (file)
@@ -7,6 +7,8 @@
 #include "error.h"
 #include "hooks.h"
 
+FILE *logfile;
+
 char *sevtostring(int severity) {
   switch(severity) {
     case ERR_DEBUG:
@@ -32,22 +34,42 @@ char *sevtostring(int severity) {
   }
 }
 
+void reopen_logfile(int hooknum, void *arg) {
+  if (logfile)
+    fclose(logfile);
+  
+  logfile=fopen("newserv.log","a");
+}
+
+void init_logfile() {
+  logfile=fopen("newserv.log","a");
+  registerhook(HOOK_CORE_SIGUSR1, reopen_logfile);
+}
+
 void Error(char *source, int severity, char *reason, ... ) {
   char buf[512];
   va_list va;
   struct tm *tm;
   time_t now;
   char timebuf[100];
-  
+  struct error_event evt;
+    
   va_start(va,reason);
   vsnprintf(buf,512,reason,va);
   va_end(va);
   
+  evt.severity=severity;
+  evt.message=buf;
+  evt.source=source;
+  triggerhook(HOOK_CORE_ERROR, &evt);
+  
   if (severity>ERR_DEBUG) {
     now=time(NULL);
     tm=gmtime(&now);
     strftime(timebuf,100,"%Y-%m-%d %H:%M:%S",tm);
     fprintf(stderr,"[%s] %s(%s): %s\n",timebuf,sevtostring(severity),source,buf);
+    if (logfile) 
+      fprintf(logfile,"[%s] %s(%s): %s\n",timebuf,sevtostring(severity),source,buf);
   }
   
   if (severity>=ERR_STOP) {