libassa 3.5.1
Loading...
Searching...
No Matches
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
38typedef unsigned char u_char;
39typedef unsigned short u_short;
40typedef unsigned int u_int;
41typedef unsigned long u_long;
42
43#define _BSDTYPES_DEFINED
44
45#endif /* ! def _BSDTYPES_DEFINED */
46
47using std::string;
48using std::ostream;
49
50#include "assa/LogMask.h"
51
54#if defined (WIN32)
55
56typedef 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
82typedef int handler_t;
83
84#endif // ifdef WIN32
85
86
87namespace ASSA {
88
89class Reactor;
90
91//---------------------------------------------------------------------------
92// Utilities that don't fit anywhere else
93//---------------------------------------------------------------------------
94
101 {
102 return (socket_ != BAD_HANDLER);
103 }
104
109 {
111 }
112
115 inline int get_errno ()
116 {
117 int myerrno;
118#if defined (WIN32)
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)
132#else
134#endif
135 }
136
137//---------------------------------------------------------------------------
138// Class Logger_Impl
139//---------------------------------------------------------------------------
140
142public:
149 static const unsigned int LOGGER_MAXLINE = 6660;
150
151public:
152 Logger_Impl ();
153 virtual ~Logger_Impl () { /* empty */ }
154
157
160
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
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_,
181
183 virtual int log_open (const char* appname_,
184 const char* logfname_,
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;
203protected:
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_,
209
226 char* format_msg (size_t expected_sz_,
227 const char* fmt_,
229 bool& release_);
230
231protected:
234
237
240
243
246
248 int m_tz;
249};
250
251inline
254 : m_indent_step (1),
255 m_groups (0),
256 m_tmflg (false),
257 m_tz (1)
258{
259 /* no-op */
260}
261
262inline int
264log_open (u_long /* groups_ */)
265{
266 errno = ENOSYS;
267 return -1;
268}
269
270inline int
272log_open (const char*, /* logfname_ */
273 u_long, /* groups_ */
274 u_long /* maxsize_ */)
275{
276 errno = ENOSYS;
277 return -1;
278}
279
280inline int
282log_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 */
Bit mask used by Logger.
#define BAD_HANDLER
Sort out WIN32/mingw oddities.
Definition Logger_Impl.h:81
unsigned long u_long
Definition Logger_Impl.h:41
unsigned short u_short
Definition Logger_Impl.h:39
int handler_t
Definition Logger_Impl.h:82
unsigned int u_int
Definition Logger_Impl.h:40
unsigned char u_char
Definition Logger_Impl.h:38
A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32
char * format_msg(size_t expected_sz_, const char *fmt_, va_list vap_, bool &release_)
Format and put the message in the buffer.
virtual u_short indent_func_name(ostream &sink_, const string &funcname_, size_t indent_level_, marker_t type_)
virtual int log_close(void)=0
bool group_enabled(Group g_) const
void enable_all_groups(void)
u_short m_indent_step
Indentation step.
int m_tz
Timezone: 0-GMT, 1-Local.
u_long m_groups
Enabled groups.
virtual void log_resync(void)
bool timestamp_enabled(void) const
void disable_all_groups(void)
string m_logfname
Log file name.
static char m_msgbuf[LOGGER_MAXLINE]
Static buffer for formatted message.
void set_indent_step(u_short step_)
virtual ~Logger_Impl()
void enable_timestamp(void)
virtual int log_msg(Group g_, size_t indent_level_, const string &func_name_, size_t expected_sz_, const char *fmt_, va_list)=0
void disable_groups(u_long g_)
u_short get_indent_step(void) const
void disable_timestamp(void)
void enable_group(Group g_)
static const unsigned int LOGGER_MAXLINE
Maximum length of the formatted message.
void set_timezone(int zone_)
virtual int log_open(u_long groups_)
Open StdErr Logger.
void disable_group(Group g_)
virtual int log_func(Group g_, size_t indent_level_, const string &func_name_, marker_t type_)=0
virtual u_short add_timestamp(ostream &sink_)
void enable_groups(u_long g_)
bool m_tmflg
Timestamp on/off flag.
void set_errno(int new_errno_)
Set error number in a portable way.
marker_t
Definition LogMask.h:67
Group
Definition LogMask.h:25
@ ALL
All messages: library + application
Definition LogMask.h:62
bool is_valid_handler(handler_t socket_)
Detect socket() error in a portable way.
void disable_handler(handler_t &socket_)
Set socket descriptor to invalid value in a portable way.
int get_errno()
Fetch error number in a portable way.