00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _LOG4CXX_DB_MYSQL_APPENDER_H
00018 #define _LOG4CXX_DB_MYSQL_APPENDER_H
00019
00020 #include "StLoggerConfig.h"
00021 #if 1
00022
00023
00024 #include <log4cxx/helpers/exception.h>
00025 #include <log4cxx/appenderskeleton.h>
00026 #include <log4cxx/spi/loggingevent.h>
00027 #include <list>
00028 #ifdef HAVE_MS_MYSQL
00029 #include <windows.h>
00030 #endif
00031
00032 #include "mysql.h"
00033 namespace log4cxx
00034 {
00035 namespace db
00036 {
00037 #if 0
00038 class LOG4CXX_EXPORT SQLException : public helpers::Exception
00039 {
00040 public:
00041 SQLException(int code) : code(code) {}
00042 virtual String getMessage() { return String(); }
00043
00044 int code;
00045 };
00046 #endif
00047 class MySQLAppender;
00048 typedef helpers::ObjectPtrT<MySQLAppender> MySQLAppenderPtr;
00049
00095 #ifndef SQLHDBC
00096 #define SQLHDBC MYSQL*
00097 #endif
00098 class LOG4CXX_EXPORT MySQLAppender : public AppenderSkeleton
00099 {
00100 protected:
00104 String databaseURL;
00105
00109 String databaseUser;
00110
00114 String databasePassword;
00115
00123 MYSQL *connection;
00124
00134 String sqlStatement;
00135
00140 size_t bufferSize;
00141
00145 std::list<spi::LoggingEventPtr> buffer;
00146 unsigned long fLastId;
00147 bool fIsConnectionOpen;
00148
00149 public:
00150 DECLARE_LOG4CXX_OBJECT(MySQLAppender)
00151 BEGIN_LOG4CXX_CAST_MAP()
00152 LOG4CXX_CAST_ENTRY(MySQLAppender)
00153 LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
00154 END_LOG4CXX_CAST_MAP()
00155
00156 MySQLAppender();
00157 virtual ~MySQLAppender();
00158
00162 virtual void setOption(const String& option, const String& value);
00163
00167 void append(const spi::LoggingEventPtr& event);
00168
00177 protected:
00178 String getLogStatement(const spi::LoggingEventPtr& event);
00179
00180 #if (STAR_LOG4CXX_VERSION == 10)
00181 protected:
00182 virtual void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p);
00183 #endif
00184
00193 unsigned int execute(const String& sql) ;
00194
00202 virtual void closeConnection();
00203
00210 virtual MYSQL *getConnection() ;
00211
00216 public:
00217 virtual void close();
00218
00226 void flushBuffer();
00227
00231
00232 virtual bool requiresLayout() const
00233 { return true; }
00234
00238 void setSql(const String& s);
00239
00243 inline const String& getSql() const
00244 { return sqlStatement; }
00245
00246
00247 inline void setUser(const String& user)
00248 { databaseUser = user; }
00249
00250
00251 inline void setURL(const String& url)
00252 { databaseURL = url; }
00253
00254
00255 inline void setPassword(const String& password)
00256 { databasePassword = password; }
00257
00258
00259 inline void setBufferSize(size_t newBufferSize)
00260 { bufferSize = newBufferSize; }
00261
00262 inline const String& getUser() const
00263 { return databaseUser; }
00264
00265
00266 inline const String& getURL() const
00267 { return databaseURL; }
00268
00269
00270 inline const String& getPassword() const
00271 { return databasePassword; }
00272
00273 inline size_t getBufferSize() const
00274 { return bufferSize; }
00275 };
00276 }
00277 };
00278
00279 #endif // HAVE_MYSQL
00280 #endif // _LOG4CXX_DB_MYSQL_APPENDER_H