StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StUCMAppender.h
1 /***************************************************************************
2  StUCMAppender.h - class StUCMAppender
3  -------------------
4  begin : Julu 2008
5  copyright : (C) 2008 by Valeri Fine
6  email : bnl.gov
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_UCM_APPENDER_H
18 #define _LOG4CXX_UCM_APPENDER_H
19 #ifdef _UCMLOGGER_
20 #include "StLoggerConfig.h"
21 
22 #include <log4cxx/helpers/exception.h>
23 #include <log4cxx/appenderskeleton.h>
24 #include <log4cxx/spi/loggingevent.h>
25 #include <list>
26 
27 namespace TxLogging {
28  class TxEventLog;
29 }
30 
31 namespace log4cxx
32 {
33  namespace db
34  {
35 #if REDUNDANT_EXCEPTION
36  class LOG4CXX_EXPORT UCMException : public helpers::Exception
37  {
38  public:
39  UCMException(int code) : code(code) {}
40  virtual String getMessage() { return String(); }
41  ~UCMException() {}
42  int code;
43  };
44 #endif
45 
46  class StUCMAppender;
47 #if (STAR_LOG4CXX_VERSION != 10)
48  typedef helpers::ObjectPtrT<StUCMAppender> StUCMAppenderPtr;
49 #endif
50 
96  class LOG4CXX_EXPORT StUCMAppender : public AppenderSkeleton
97  {
98  protected:
102  String databaseURL;
103 
107  String databaseUser;
108 
112  String databasePassword;
113 
121  TxLogging::TxEventLog *connection;
122 
126  String technology;
127 
142  size_t bufferSize;
143 
147  std::list<spi::LoggingEventPtr> buffer;
148  unsigned long fLastId;
149  bool fIsConnectionOpen;
150 #if (STAR_LOG4CXX_VERSION == 10)
151  protected:
152  virtual void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p);
153 #endif
154 
155  public:
156  DECLARE_LOG4CXX_OBJECT(StUCMAppender)
157  BEGIN_LOG4CXX_CAST_MAP()
158  LOG4CXX_CAST_ENTRY(StUCMAppender)
159  LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
160  END_LOG4CXX_CAST_MAP()
161 
162  StUCMAppender(const char *mode="F");
163  virtual ~StUCMAppender();
164 
168  virtual void setOption(const String& option, const String& value);
169 
173  void append(const spi::LoggingEventPtr& event);
174 
183  protected:
184  String getLogStatement(const spi::LoggingEventPtr& event);
185 // String getLogStatement(const spi::LoggingEventPtr& event) const;
186 
194  virtual void closeConnection();
195 
202  virtual TxLogging::TxEventLog *getConnection() /*throw(SQLException)*/;
203 
208  public:
209  virtual void close();
210 
211  /* loops through the buffer of LoggingEvents, gets a
212  * sql string from getLogStatement() and sends it to execute().
213  * Errors are sent to the errorHandler.
214  *
215  * If a statement fails the LoggingEvent stays in the buffer!
216  */
217  void flushBuffer();
218 
237 // virtual bool requiresLayout()
238  virtual bool requiresLayout() const
239  { return true; }
240 
241  inline void setUser(const String& user)
242  { databaseUser = user; }
243 
244 
245  inline void setURL(const String& url)
246  { databaseURL = url; }
247 
248 
249  inline void setPassword(const String& password)
250  { databasePassword = password; }
251 
252 
253  inline void setBufferSize(size_t newBufferSize)
254  { bufferSize = newBufferSize; }
255 
256  inline const String& getUser() const
257  { return databaseUser; }
258 
259 
260  inline const String& getURL() const
261  { return databaseURL; }
262 
263 
264  inline const String& getPassword() const
265  { return databasePassword; }
266 
267  inline size_t getBufferSize() const
268  { return bufferSize; }
269  }; // class StUCMAppender
270 #if (STAR_LOG4CXX_VERSION == 10)
271  LOG4CXX_PTR_DEF(StUCMAppender);
272 #endif
273  } // namespace db
274 }; // namespace log4cxx
275 #endif
276 #endif // _LOG4CXX_UCM_APPENDER_H