Apache Log4cxx  Version 1.7.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 #include <log4cxx/log4cxx.h>
22 
26 
27 #if LOG4CXX_EVENTS_AT_EXIT
28 #include <log4cxx/private/atexitregistry.h>
29 #endif
30 
31 #include <list>
32 #include <memory>
33 
34 namespace LOG4CXX_NS
35 {
36 namespace db
37 {
38 class LOG4CXX_EXPORT SQLException : public LOG4CXX_NS::helpers::Exception
39 {
40  public:
41  SQLException(short fHandleType,
42  void* hInput, const char* prolog,
43  LOG4CXX_NS::helpers::Pool& p);
44  SQLException(const char* msg);
46  private:
47  const char* formatMessage(short fHandleType,
48  void* hInput, const char* prolog,
49  LOG4CXX_NS::helpers::Pool& p);
50 };
51 
142 class LOG4CXX_EXPORT ODBCAppender : public AppenderSkeleton
143 {
144  public:
150 
151  typedef void* SQLHDBC;
152  typedef void* SQLHENV;
153  typedef void* SQLHANDLE;
154  typedef short SQLSMALLINT;
155 
157  virtual ~ODBCAppender();
158 
177  void setOption(const LogString& option, const LogString& value) override;
178 
182  void activateOptions(helpers::Pool& p) override;
183 
187  void append(const spi::LoggingEventPtr& event, helpers::Pool&) override;
188 
189  protected:
190 #if LOG4CXX_ABI_VERSION <= 15
195  helpers::Pool& p) const;
196 
201  virtual void execute(const LogString& sql,
202  LOG4CXX_NS::helpers::Pool& p) /*throw(SQLException)*/;
203 #endif
211  virtual void closeConnection(SQLHDBC con);
212 
219  virtual SQLHDBC getConnection(LOG4CXX_NS::helpers::Pool& p) /*throw(SQLException)*/;
220 
225  public:
226  void close() override;
227 
235  virtual void flushBuffer(LOG4CXX_NS::helpers::Pool& p);
236 
240  bool requiresLayout() const override;
241 
245  void setSql(const LogString& s);
246 
250  const LogString& getSql() const;
251 
252 
253  void setUser(const LogString& user);
254 
255  void setURL(const LogString& url);
256 
257  void setPassword(const LogString& password);
258 
259  void setBufferSize(size_t newBufferSize);
260 
261  const LogString& getUser() const;
262 
263  const LogString& getURL() const;
264 
265  const LogString& getPassword() const;
266 
267  size_t getBufferSize() const;
268  private:
269  ODBCAppender(const ODBCAppender&);
270  ODBCAppender& operator=(const ODBCAppender&);
271 #if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR || defined(WIN32) || defined(_WIN32)
272  static void encode(wchar_t** dest, const LogString& src,
273  LOG4CXX_NS::helpers::Pool& p);
274 #endif
275  static void encode(unsigned short** dest, const LogString& src,
276  LOG4CXX_NS::helpers::Pool& p);
277 
278  protected:
279  struct ODBCAppenderPriv;
280 }; // class ODBCAppender
282 
283 } // namespace db
284 } // namespace log4cxx
285 
286 #endif // _LOG4CXX_DB_ODBC_APPENDER_H
Implementation base class for all appenders.
Definition: appenderskeleton.h:41
The ODBCAppender sends log events to a database.
Definition: odbcappender.h:143
virtual SQLHDBC getConnection(log4cxx::helpers::Pool &p)
Override this to link with your connection pooling system.
virtual void flushBuffer(log4cxx::helpers::Pool &p)
loops through the buffer of LoggingEvents, gets a sql string from getLogStatement() and sends it to e...
bool requiresLayout() const override
Does this appender require a layout?
virtual void closeConnection(SQLHDBC con)
Override this to return the connection to a pool, or to clean up the resource.
void * SQLHENV
Definition: odbcappender.h:152
void setBufferSize(size_t newBufferSize)
void setUser(const LogString &user)
LogString getLogStatement(const spi::LoggingEventPtr &event, helpers::Pool &p) const
To be removed.
void setPassword(const LogString &password)
const LogString & getURL() const
void setURL(const LogString &url)
void * SQLHDBC
Definition: odbcappender.h:151
const LogString & getSql() const
Returns pre-formated statement eg: insert into LogTable (msg) values ("%m")
void * SQLHANDLE
Definition: odbcappender.h:153
const LogString & getPassword() const
const LogString & getUser() const
void close() override
Closes the appender, flushing the buffer first then closing the default connection if it is open.
virtual void execute(const LogString &sql, log4cxx::helpers::Pool &p)
To be removed.
void setSql(const LogString &s)
Set pre-formated statement eg: insert into LogTable (msg) values ("%m")
short SQLSMALLINT
Definition: odbcappender.h:154
size_t getBufferSize() const
Definition: odbcappender.h:39
SQLException(const char *msg)
SQLException(const SQLException &src)
SQLException(short fHandleType, void *hInput, const char *prolog, log4cxx::helpers::Pool &p)
Definition: pool.h:33
LOG4CXX_PTR_DEF(ODBCAppender)
std::shared_ptr< LoggingEvent > LoggingEventPtr
Definition: appender.h:31
std::basic_string< logchar > LogString
Definition: logstring.h:60
#define LOG4CXX_CAST_ENTRY(Interface)
Definition: object.h:154
#define END_LOG4CXX_CAST_MAP()
Definition: object.h:148
#define DECLARE_LOG4CXX_OBJECT(object)
Definition: object.h:41
#define LOG4CXX_CAST_ENTRY_CHAIN(Interface)
Definition: object.h:160
#define BEGIN_LOG4CXX_CAST_MAP()
Definition: object.h:142