Apache log4cxx Version 0.13.0
odbcappender.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef _LOG4CXX_DB_ODBC_APPENDER_H
19#define _LOG4CXX_DB_ODBC_APPENDER_H
20
21#if defined(_MSC_VER)
22 #pragma warning ( push )
23 #pragma warning ( disable: 4231 4251 4275 4786 )
24#endif
25
26
27#include <log4cxx/log4cxx.h>
28
32#include <list>
33
34namespace log4cxx
35{
36namespace db
37{
38class LOG4CXX_EXPORT SQLException : public log4cxx::helpers::Exception
39{
40 public:
41 SQLException(short fHandleType,
42 void* hInput, const char* prolog,
44 SQLException(const char* msg);
46 private:
47 const char* formatMessage(short fHandleType,
48 void* hInput, const char* prolog,
50};
51
98class LOG4CXX_EXPORT ODBCAppender : public AppenderSkeleton
99{
100 protected:
105
110
115
116 typedef void* SQLHDBC;
117 typedef void* SQLHENV;
118 typedef void* SQLHANDLE;
119 typedef short SQLSMALLINT;
120
130
141
147
151 std::list<spi::LoggingEventPtr> buffer;
152
153 public:
159
161 virtual ~ODBCAppender();
162
166 virtual void setOption(const LogString& option, const LogString& value);
167
171 virtual void activateOptions(log4cxx::helpers::Pool& p);
172
176 void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool&);
177
186 protected:
187 LogString getLogStatement(const spi::LoggingEventPtr& event,
188 helpers::Pool& p) const;
189
198 virtual void execute(const LogString& sql,
199 log4cxx::helpers::Pool& p) /*throw(SQLException)*/;
200
208 virtual void closeConnection(SQLHDBC con);
209
216 virtual SQLHDBC getConnection(log4cxx::helpers::Pool& p) /*throw(SQLException)*/;
217
222 public:
223 virtual void close();
224
232 virtual void flushBuffer(log4cxx::helpers::Pool& p);
233
237 virtual bool requiresLayout() const
238 {
239 return true;
240 }
241
245 void setSql(const LogString& s);
246
250 inline const LogString& getSql() const
251 {
252 return sqlStatement;
253 }
254
255
256 inline void setUser(const LogString& user)
257 {
258 databaseUser = user;
259 }
260
261
262 inline void setURL(const LogString& url)
263 {
264 databaseURL = url;
265 }
266
267
268 inline void setPassword(const LogString& password)
269 {
270 databasePassword = password;
271 }
272
273
274 inline void setBufferSize(size_t newBufferSize)
275 {
276 bufferSize = newBufferSize;
277 }
278
279 inline const LogString& getUser() const
280 {
281 return databaseUser;
282 }
283
284
285 inline const LogString& getURL() const
286 {
287 return databaseURL;
288 }
289
290
291 inline const LogString& getPassword() const
292 {
293 return databasePassword;
294 }
295
296 inline size_t getBufferSize() const
297 {
298 return bufferSize;
299 }
300 private:
302 ODBCAppender& operator=(const ODBCAppender&);
303#if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR_T || defined(WIN32) || defined(_WIN32)
304 static void encode(wchar_t** dest, const LogString& src,
306#endif
307 static void encode(unsigned short** dest, const LogString& src,
309}; // class ODBCAppender
311
312} // namespace db
313} // namespace log4cxx
314
315#if defined(_MSC_VER)
316 #pragma warning ( pop )
317#endif
318
319#endif // _LOG4CXX_DB_ODBC_APPENDER_H
Implementation base class for all appenders.
Definition: appenderskeleton.h:46
Definition: odbcappender.h:99
LogString databaseUser
User to connect as for default connection handling.
Definition: odbcappender.h:109
void * SQLHENV
Definition: odbcappender.h:117
const LogString & getUser() const
Definition: odbcappender.h:279
void setBufferSize(size_t newBufferSize)
Definition: odbcappender.h:274
void setUser(const LogString &user)
Definition: odbcappender.h:256
LogString sqlStatement
Stores the string given to the pattern layout for conversion into a SQL statement,...
Definition: odbcappender.h:140
const LogString & getSql() const
Returns pre-formated statement eg: insert into LogTable (msg) values ("%m")
Definition: odbcappender.h:250
void setPassword(const LogString &password)
Definition: odbcappender.h:268
const LogString & getPassword() const
Definition: odbcappender.h:291
void setURL(const LogString &url)
Definition: odbcappender.h:262
void * SQLHDBC
Definition: odbcappender.h:116
void * SQLHANDLE
Definition: odbcappender.h:118
LogString databasePassword
User to use for default connection handling.
Definition: odbcappender.h:114
LogString databaseURL
URL of the DB for default connection handling.
Definition: odbcappender.h:104
SQLHENV env
Definition: odbcappender.h:129
std::list< spi::LoggingEventPtr > buffer
ArrayList holding the buffer of Logging Events.
Definition: odbcappender.h:151
void setSql(const LogString &s)
Set pre-formated statement eg: insert into LogTable (msg) values ("%m")
SQLHDBC connection
Connection used by default.
Definition: odbcappender.h:128
size_t bufferSize
size of LoggingEvent buffer before writing to the database.
Definition: odbcappender.h:146
const LogString & getURL() const
Definition: odbcappender.h:285
short SQLSMALLINT
Definition: odbcappender.h:119
size_t getBufferSize() const
Definition: odbcappender.h:296
Definition: odbcappender.h:39
SQLException(const char *msg)
SQLException(const SQLException &src)
SQLException(short fHandleType, void *hInput, const char *prolog, log4cxx::helpers::Pool &p)
The class Exception and its subclasses indicate conditions that a reasonable application might want t...
Definition: exception.h:38
Definition: pool.h:33
LOG4CXX_PTR_DEF(ODBCAppender)
std::shared_ptr< LoggingEvent > LoggingEventPtr
Definition: appender.h:38
Definition: messagehandler.h:23
std::basic_string< logchar > LogString
Definition: logstring.h:66
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:153
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:147
#define DECLARE_LOG4CXX_OBJECT(object)
Definition: object.h:39
#define LOG4CXX_CAST_ENTRY_CHAIN(Interface)
Definition: object.h:159
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:141