rllib  1
rlevent.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  rlevent.cpp - description
3  -------------------
4  begin : Wed Dec 18 2002
5  copyright : (C) 2002 by R. Lehrig
6  email : lehrig@t-online.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This library is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as *
13  * published by the Free Software Foundation *
14  * *
15  ***************************************************************************/
16 #include "rlevent.h"
17 #include "rlsocket.h"
18 #include "rltime.h"
19 #include "rlcutil.h"
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <stdarg.h>
24 
25 static rlSocket toEventLogServer("localhost",-1,1); // standard localhost disabled
26 static rlTime mytime;
27 static char rlmodule[32];
28 static char rllocation[rlMAX_EVENT];
29 static char rlmessage[rlMAX_EVENT];
30 #ifdef __VMS
31 static char rlfinal[rlMAX_EVENT*4];
32 #else
33 static char rlfinal[rlMAX_EVENT];
34 #endif
35 
36 void rlEventInit(int ac, char **av, const char *module)
37 {
38  const char *cptr;
39 
40  rlwsa();
41  for(int i=0; i<ac; i++)
42  {
43  cptr = av[i];
44  if(strncmp("-eventhost=",cptr,11) == 0) toEventLogServer.setAdr(&cptr[11]);
45  if(strncmp("-eventport=",cptr,11) == 0) toEventLogServer.setPort(atoi(&cptr[11]));
46  }
47  rlstrncpy(rlmodule,module,sizeof(rlmodule)-1);
48 }
49 
50 void rlSetEventLocation(const char *file, int line)
51 {
52 #ifdef RLWIN32
53  const char *cptr;
54 
55  if(strchr(file,'\\') == NULL) cptr = NULL;
56  else cptr = strrchr(file,'\\');
57  if(cptr != NULL) cptr++;
58  else cptr = file;
59 #endif
60 #ifdef __VMS
61  const char *cptr;
62 
63  if(strchr(file,']') == NULL) cptr = NULL;
64  else cptr = strrchr(file,']');
65  if(cptr != NULL) cptr++;
66  else cptr = file;
67 #endif
68 
69 #ifdef RLUNIX
70  snprintf(rllocation,sizeof(rllocation)-1,":%s:%d",file,line);
71 #endif
72 
73 #ifdef __VMS
74  sprintf(rllocation,":%s:%d",file,line);
75 #endif
76 
77 #ifdef RLWIN32
78  _snprintf(rllocation,sizeof(rllocation)-1,":%s:%d",file,line);
79 #endif
80 }
81 
82 void rlEventPrintf(int event_type, const char *format, ...)
83 {
84  if(toEventLogServer.getPort() <= 0) return;
85  va_list ap;
86  va_start(ap,format);
87  rlvsnprintf(rlmessage,sizeof(rlmessage)-1,format,ap);
88  va_end(ap);
89 
90  if(event_type < 0 ) event_type = rlError;
91  if(event_type >= rlEVENT_SIZE) event_type = rlError;
93 #ifdef RLUNIX
94  snprintf(rlfinal,sizeof(rlfinal)-1,"%s %s %s %s%s\n",
95  rlevent_name[event_type],
97  rlmessage,
98  rlmodule,
100  );
101 #endif
102 #ifdef __VMS
103  sprintf(rlfinal,"%s %s %s %s%s\n",
104  rlevent_name[event_type],
106  rlmessage,
107  rlmodule,
108  rllocation
109  );
110  rlfinal[rlMAX_EVENT-1] = '\0';
111 #endif
112 #ifdef RLWIN32
113  _snprintf(rlfinal,sizeof(rlfinal)-1,"%s %s %s %s%s\n",
114  rlevent_name[event_type],
116  rlmessage,
117  rlmodule,
118  rllocation
119  );
120 #endif
122  {
124  }
125  else
126  {
129  {
131  } // else give up
132  }
133 }
134 
void rlEventPrintf(int event_type, const char *format,...)
Definition: rlevent.cpp:82
const char * getTimeString()
Definition: rltime.cpp:106
void getLocalTime()
Definition: rltime.cpp:342
static char rlmessage[rlMAX_EVENT]
Definition: rlevent.cpp:29
#define rlMAX_EVENT
Definition: rlevent.h:26
static const char rlevent_name[][4]
Definition: rlevent.h:28
static char rlfinal[rlMAX_EVENT *4]
Definition: rlevent.cpp:31
void rlSetEventLocation(const char *file, int line)
Definition: rlevent.cpp:50
void setPort(int port)
Definition: rlsocket.cpp:176
static rlTime mytime
Definition: rlevent.cpp:26
int rlvsnprintf(char *text, int len, const char *format, va_list ap)
Definition: rlcutil.cpp:197
static char rlmodule[32]
Definition: rlevent.cpp:27
void rlEventInit(int ac, char **av, const char *module)
Definition: rlevent.cpp:36
char * rlstrncpy(char *dest, const char *source, int n)
Definition: rlcutil.cpp:169
int getPort()
Definition: rlsocket.cpp:181
int connect()
Definition: rlsocket.cpp:321
int isConnected()
Definition: rlsocket.cpp:559
void setAdr(const char *adr)
Definition: rlsocket.cpp:168
int rlwsa()
Definition: rlsocket.cpp:68
Definition: rltime.h:25
static char rllocation[rlMAX_EVENT]
Definition: rlevent.cpp:28
static rlSocket toEventLogServer("localhost",-1, 1)
int printf(const char *format,...)
Definition: rlsocket.cpp:586