StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MySQLAppender.h
1 /***************************************************************************
2  MySQLAppender.h - class MySQLAppender
3  -------------------
4  begin : jeu mai 8 2003
5  copyright : (C) 2003 by Michael CATANZARITI
6  email : mcatan@free.fr
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * Copyright (C) The Apache Software Foundation. All rights reserved. *
11  * *
12  * This software is published under the terms of the Apache Software *
13  * License version 1.1, a copy of which has been included with this *
14  * distribution in the LICENSE.txt file. *
15  ***************************************************************************/
16 
17 #ifndef _LOG4CXX_DB_MYSQL_APPENDER_H
18 #define _LOG4CXX_DB_MYSQL_APPENDER_H
19 
20 #include "StLoggerConfig.h"
21 #if 1
22 // def HAVE_MYSQL
23 
24 #include <log4cxx/helpers/exception.h>
25 #include <log4cxx/appenderskeleton.h>
26 #include <log4cxx/spi/loggingevent.h>
27 #include <list>
28 #ifdef HAVE_MS_MYSQL
29 #include <windows.h>
30 #endif
31 
32 #include "mysql.h"
33 namespace log4cxx
34 {
35  namespace db
36  {
37 #if 0
38  class LOG4CXX_EXPORT SQLException : public helpers::Exception
39  {
40  public:
41  SQLException(int code) : code(code) {}
42  virtual String getMessage() { return String(); }
43 
44  int code;
45  };
46 #endif
47  class MySQLAppender;
48  typedef helpers::ObjectPtrT<MySQLAppender> MySQLAppenderPtr;
49 
95 #ifndef SQLHDBC
96 #define SQLHDBC MYSQL*
97 #endif
98  class LOG4CXX_EXPORT MySQLAppender : public AppenderSkeleton
99  {
100  protected:
104  String databaseURL;
105 
109  String databaseUser;
110 
115 
123  MYSQL *connection;
124 
134  String sqlStatement;
135 
140  size_t bufferSize;
141 
145  std::list<spi::LoggingEventPtr> buffer;
146  unsigned long fLastId;
147  bool fIsConnectionOpen;
148 
149  public:
150  DECLARE_LOG4CXX_OBJECT(MySQLAppender)
151  BEGIN_LOG4CXX_CAST_MAP()
152  LOG4CXX_CAST_ENTRY(MySQLAppender)
153  LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
154  END_LOG4CXX_CAST_MAP()
155 
156  MySQLAppender();
157  virtual ~MySQLAppender();
158 
162  virtual void setOption(const String& option, const String& value);
163 
167  void append(const spi::LoggingEventPtr& event);
168 
177  protected:
178  String getLogStatement(const spi::LoggingEventPtr& event);
179 // String getLogStatement(const spi::LoggingEventPtr& event) const;
180 #if (STAR_LOG4CXX_VERSION == 10)
181  protected:
182  virtual void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p);
183 #endif
184 
193  unsigned int execute(const String& sql) /*throw(SQLException)*/;
194 
202  virtual void closeConnection();
203 
210  virtual MYSQL *getConnection() /*throw(SQLException)*/;
211 
216  public:
217  virtual void close();
218 
226  void flushBuffer();
227 
231 // virtual bool requiresLayout()
232  virtual bool requiresLayout() const
233  { return true; }
234 
238  void setSql(const String& s);
239 
243  inline const String& getSql() const
244  { return sqlStatement; }
245 
246 
247  inline void setUser(const String& user)
248  { databaseUser = user; }
249 
250 
251  inline void setURL(const String& url)
252  { databaseURL = url; }
253 
254 
255  inline void setPassword(const String& password)
256  { databasePassword = password; }
257 
258 
259  inline void setBufferSize(size_t newBufferSize)
260  { bufferSize = newBufferSize; }
261 
262  inline const String& getUser() const
263  { return databaseUser; }
264 
265 
266  inline const String& getURL() const
267  { return databaseURL; }
268 
269 
270  inline const String& getPassword() const
271  { return databasePassword; }
272 
273  inline size_t getBufferSize() const
274  { return bufferSize; }
275  }; // class MySQLAppender
276  } // namespace db
277 }; // namespace log4cxx
278 
279 #endif // HAVE_MYSQL
280 #endif // _LOG4CXX_DB_MYSQL_APPENDER_H
std::list< spi::LoggingEventPtr > buffer
virtual bool requiresLayout() const
const String & getSql() const