libassa
3.5.1
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
assa
Logger_Impl.h
Go to the documentation of this file.
1
// -*- c++ -*-
2
//------------------------------------------------------------------------------
3
// Logger_Impl.h
4
//------------------------------------------------------------------------------
5
// $Id: Logger_Impl.h,v 1.12 2012/05/21 03:20:39 vlg Exp $
6
//------------------------------------------------------------------------------
7
// Copyright (c) 2001 Vladislav Grinchenko
8
//
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Library General Public
11
// License as published by the Free Software Foundation; either
12
// version 2 of the License, or (at your option) any later version.
13
//------------------------------------------------------------------------------
14
#ifndef LOGGER_IMPL_H
15
#define LOGGER_IMPL_H
16
17
#include <errno.h>
18
#include <cstdarg>
19
#include <string>
20
#include <stdio.h>
21
22
#if defined(sun)
23
#include <sys/varargs.h>
// va_list
24
#endif
25
26
#if defined (__CYGWIN32__) || defined (__NetBSD__) || defined (WIN32) || defined (__GLIBC__)
27
# include <stdarg.h>
28
#endif
29
30
#if defined(WIN32)
31
# include <winsock2.h>
/* select(3) */
32
#endif
33
34
/* Also defined in winsock.h, winsock2.h, gmon.h and in cygwin's sys/types
35
*/
36
#if !defined ( _BSDTYPES_DEFINED )
37
38
typedef
unsigned
char
u_char
;
39
typedef
unsigned
short
u_short
;
40
typedef
unsigned
int
u_int
;
41
typedef
unsigned
long
u_long
;
42
43
#define _BSDTYPES_DEFINED
44
45
#endif
/* ! def _BSDTYPES_DEFINED */
46
47
using
std::string;
48
using
std::ostream;
49
50
#include "
assa/LogMask.h
"
51
54
#if defined (WIN32)
55
56
typedef
SOCKET
handler_t
;
57
#define BAD_HANDLER INVALID_SOCKET
58
61
#define EINPROGRESS WSAEINPROGRESS
/* A blocking Winsock call is in
62
* progress, or the service provider
63
* is still process a callback function.
64
*/
65
#define EWOULDBLOCK WSAEWOULDBLOCK
/* The socket is marked as nonblocking
66
* and the connection cannot be completed
67
* immediately.
68
*/
69
#define EISCONN WSAEISCONN
70
71
#define ENOTSOCK WSAENOTSOCK
/* The descriptor is not a socket.
72
*/
73
#define ECONNREFUSED WSAECONNREFUSED
/* The attempt to connect was
74
* forcefully rejected.
75
*/
76
#define ETIMEDOUT WSAETIMEDOUT
/* An attempt to connect timed out
77
* without establishing connection.
78
*/
79
#else
/*--- POSIX ---*/
80
81
#define BAD_HANDLER -1
82
typedef
int
handler_t
;
83
84
#endif // ifdef WIN32
85
86
87
namespace
ASSA {
88
89
class
Reactor;
90
91
//---------------------------------------------------------------------------
92
// Utilities that don't fit anywhere else
93
//---------------------------------------------------------------------------
94
100
inline
bool
is_valid_handler
(
handler_t
socket_)
101
{
102
return
(socket_ !=
BAD_HANDLER
);
103
}
104
108
inline
void
disable_handler
(
handler_t
& socket_)
109
{
110
socket_ =
BAD_HANDLER
;
111
}
112
115
inline
int
get_errno
()
116
{
117
int
myerrno;
118
#if defined (WIN32)
119
myerrno = WSAGetLastError ();
120
#else
121
myerrno = errno;
122
#endif
123
return
myerrno;
124
}
125
128
inline
void
set_errno
(
int
new_errno_)
129
{
130
#if defined (WIN32)
131
WSASetLastError (new_errno_);
132
#else
133
errno = new_errno_;
134
#endif
135
}
136
137
//---------------------------------------------------------------------------
138
// Class Logger_Impl
139
//---------------------------------------------------------------------------
140
141
class
Logger_Impl
{
142
public
:
149
static
const
unsigned
int
LOGGER_MAXLINE
= 6660;
150
151
public
:
152
Logger_Impl
();
153
virtual
~Logger_Impl
() {
/* empty */
}
154
155
void
enable_group
(
Group
g_) {
m_groups
|= g_; }
156
void
disable_group
(
Group
g_) {
m_groups
&= ~g_; }
157
158
void
enable_groups
(
u_long
g_) {
m_groups
|= g_; }
159
void
disable_groups
(
u_long
g_) {
m_groups
&= ~g_; }
160
161
void
enable_all_groups
(
void
) {
m_groups
=
ASSA::ALL
; }
162
void
disable_all_groups
(
void
) {
m_groups
= 0; }
163
164
bool
group_enabled
(
Group
g_)
const
{
return
(
m_groups
& g_); }
165
166
void
enable_timestamp
(
void
) {
m_tmflg
=
true
; }
167
void
disable_timestamp
(
void
) {
m_tmflg
=
false
; }
168
bool
timestamp_enabled
(
void
)
const
{
return
m_tmflg
; }
169
void
set_timezone
(
int
zone_) {
m_tz
= zone_; }
170
171
void
set_indent_step
(
u_short
step_) {
m_indent_step
= step_; }
172
u_short
get_indent_step
(
void
)
const
{
return
m_indent_step
; }
173
175
virtual
int
log_open
(
u_long
groups_);
176
178
virtual
int
log_open
(
const
char
* logfname_,
179
u_long
groups_,
180
u_long
maxsize_);
181
183
virtual
int
log_open
(
const
char
* appname_,
184
const
char
* logfname_,
185
u_long
groups_,
186
u_long
maxsize_,
187
Reactor
* reactor_);
188
189
virtual
int
log_close
(
void
) = 0;
190
virtual
void
log_resync
(
void
) {
/* empty */
}
191
192
virtual
int
log_msg
(
Group
g_,
193
size_t
indent_level_,
194
const
string
& func_name_,
195
size_t
expected_sz_,
196
const
char
* fmt_,
197
va_list) = 0;
198
199
virtual
int
log_func
(
Group
g_,
200
size_t
indent_level_,
201
const
string
& func_name_,
202
marker_t
type_) = 0;
203
protected
:
204
virtual
u_short
add_timestamp
(ostream& sink_);
205
virtual
u_short
indent_func_name
(ostream& sink_,
206
const
string
& funcname_,
207
size_t
indent_level_,
208
marker_t
type_);
209
226
char
*
format_msg
(
size_t
expected_sz_,
227
const
char
* fmt_,
228
va_list vap_,
229
bool
& release_);
230
231
protected
:
233
static
char
m_msgbuf
[
LOGGER_MAXLINE
];
234
236
u_short
m_indent_step
;
237
239
u_long
m_groups
;
240
242
string
m_logfname
;
243
245
bool
m_tmflg
;
246
248
int
m_tz
;
249
};
250
251
inline
252
Logger_Impl::
253
Logger_Impl
()
254
: m_indent_step (1),
255
m_groups (0),
256
m_tmflg (false),
257
m_tz (1)
258
{
259
/* no-op */
260
}
261
262
inline
int
263
Logger_Impl::
264
log_open
(
u_long
/* groups_ */
)
265
{
266
errno = ENOSYS;
267
return
-1;
268
}
269
270
inline
int
271
Logger_Impl::
272
log_open
(
const
char
*,
/* logfname_ */
273
u_long
,
/* groups_ */
274
u_long
/* maxsize_ */
)
275
{
276
errno = ENOSYS;
277
return
-1;
278
}
279
280
inline
int
281
Logger_Impl::
282
log_open
(
const
char
*,
/* appname_ */
283
const
char
*,
/* logfname_ */
284
u_long
,
/* groups_ */
285
u_long
,
/* maxsize_ */
286
Reactor
*
/* reactor_ */
)
287
{
288
errno = ENOSYS;
289
return
-1;
290
}
291
292
}
// end namespace ASSA
293
294
#endif
/* LOGGER_IMPL_H */
Generated on Tue Mar 25 2014 04:44:25 for libassa by
1.8.1.2