rllib
1
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
lib
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
;
92
mytime.
getLocalTime
();
93
#ifdef RLUNIX
94
snprintf(
rlfinal
,
sizeof
(
rlfinal
)-1,
"%s %s %s %s%s\n"
,
95
rlevent_name
[event_type],
96
mytime.
getTimeString
(),
97
rlmessage
,
98
rlmodule
,
99
rllocation
100
);
101
#endif
102
#ifdef __VMS
103
sprintf(
rlfinal
,
"%s %s %s %s%s\n"
,
104
rlevent_name
[event_type],
105
mytime.
getTimeString
(),
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],
115
mytime.
getTimeString
(),
116
rlmessage
,
117
rlmodule
,
118
rllocation
119
);
120
#endif
121
if
(
toEventLogServer
.
isConnected
())
122
{
123
toEventLogServer
.
printf
(
"%s"
,rlfinal);
124
}
125
else
126
{
127
toEventLogServer
.
connect
();
128
if
(
toEventLogServer
.
isConnected
())
129
{
130
toEventLogServer
.
printf
(
"%s"
,rlfinal);
131
}
// else give up
132
}
133
}
134
Generated by
1.8.2