|
rllib
1
|
00001 /*************************************************************************** 00002 rlevent.cpp - description 00003 ------------------- 00004 begin : Wed Dec 18 2002 00005 copyright : (C) 2002 by Rainer Lehrig 00006 email : lehrig@t-online.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This library is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as * 00013 * published by the Free Software Foundation * 00014 * * 00015 ***************************************************************************/ 00016 #include "rlevent.h" 00017 #include "rlsocket.h" 00018 #include "rltime.h" 00019 #include "rlcutil.h" 00020 #include <stdio.h> 00021 #include <stdlib.h> 00022 #include <string.h> 00023 #include <stdarg.h> 00024 00025 static rlSocket toEventLogServer("localhost",-1,1); // standard localhost disabled 00026 static rlTime time; 00027 static char rlmodule[32]; 00028 static char rllocation[rlMAX_EVENT]; 00029 static char rlmessage[rlMAX_EVENT]; 00030 #ifdef __VMS 00031 static char rlfinal[rlMAX_EVENT*4]; 00032 #else 00033 static char rlfinal[rlMAX_EVENT]; 00034 #endif 00035 00036 void rlEventInit(int ac, char **av, const char *module) 00037 { 00038 const char *cptr; 00039 00040 rlwsa(); 00041 for(int i=0; i<ac; i++) 00042 { 00043 cptr = av[i]; 00044 if(strncmp("-eventhost=",cptr,11) == 0) toEventLogServer.setAdr(&cptr[11]); 00045 if(strncmp("-eventport=",cptr,11) == 0) toEventLogServer.setPort(atoi(&cptr[11])); 00046 } 00047 rlstrncpy(rlmodule,module,sizeof(rlmodule)-1); 00048 } 00049 00050 void rlSetEventLocation(const char *file, int line) 00051 { 00052 #ifdef RLWIN32 00053 const char *cptr; 00054 00055 cptr = strrchr(file,'\\'); 00056 if(cptr != NULL) cptr++; 00057 else cptr = file; 00058 #endif 00059 #ifdef __VMS 00060 const char *cptr; 00061 00062 cptr = strrchr(file,']'); 00063 if(cptr != NULL) cptr++; 00064 else cptr = file; 00065 #endif 00066 00067 #ifdef RLUNIX 00068 snprintf(rllocation,sizeof(rllocation)-1,":%s:%d",file,line); 00069 #endif 00070 00071 #ifdef __VMS 00072 sprintf(rllocation,":%s:%d",file,line); 00073 #endif 00074 00075 #ifdef RLWIN32 00076 _snprintf(rllocation,sizeof(rllocation)-1,":%s:%d",file,line); 00077 #endif 00078 } 00079 00080 void rlEventPrintf(int event_type, const char *format, ...) 00081 { 00082 if(toEventLogServer.getPort() <= 0) return; 00083 va_list ap; 00084 va_start(ap,format); 00085 rlvsnprintf(rlmessage,sizeof(rlmessage)-1,format,ap); 00086 va_end(ap); 00087 00088 if(event_type < 0 ) event_type = rlError; 00089 if(event_type >= rlEVENT_SIZE) event_type = rlError; 00090 time.getLocalTime(); 00091 #ifdef RLUNIX 00092 snprintf(rlfinal,sizeof(rlfinal)-1,"%s %s %s %s%s\n", 00093 rlevent_name[event_type], 00094 time.getTimeString(), 00095 rlmessage, 00096 rlmodule, 00097 rllocation 00098 ); 00099 #endif 00100 #ifdef __VMS 00101 sprintf(rlfinal,"%s %s %s %s%s\n", 00102 rlevent_name[event_type], 00103 time.getTimeString(), 00104 rlmessage, 00105 rlmodule, 00106 rllocation 00107 ); 00108 rlfinal[rlMAX_EVENT-1] = '\0'; 00109 #endif 00110 #ifdef RLWIN32 00111 _snprintf(rlfinal,sizeof(rlfinal)-1,"%s %s %s %s%s\n", 00112 rlevent_name[event_type], 00113 time.getTimeString(), 00114 rlmessage, 00115 rlmodule, 00116 rllocation 00117 ); 00118 #endif 00119 if(toEventLogServer.isConnected()) 00120 { 00121 toEventLogServer.printf("%s",rlfinal); 00122 } 00123 else 00124 { 00125 toEventLogServer.connect(); 00126 if(toEventLogServer.isConnected()) 00127 { 00128 toEventLogServer.printf("%s",rlfinal); 00129 } // else give up 00130 } 00131 } 00132
1.7.5.1