StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
log4cxx::db::MySQLAppender Class Reference
Inheritance diagram for log4cxx::db::MySQLAppender:

Public Member Functions

virtual void setOption (const String &option, const String &value)
 
void append (const spi::LoggingEventPtr &event)
 
virtual void close ()
 
void flushBuffer ()
 
virtual bool requiresLayout () const
 
void setSql (const String &s)
 
const String & getSql () const
 
void setUser (const String &user)
 
void setURL (const String &url)
 
void setPassword (const String &password)
 
void setBufferSize (size_t newBufferSize)
 
const String & getUser () const
 
const String & getURL () const
 
const String & getPassword () const
 
size_t getBufferSize () const
 

Protected Member Functions

String getLogStatement (const spi::LoggingEventPtr &event)
 
unsigned int execute (const String &sql)
 
virtual void closeConnection ()
 
virtual MYSQL * getConnection ()
 

Protected Attributes

String databaseURL
 
String databaseUser
 
String databasePassword
 
MYSQL * connection
 
String sqlStatement
 
size_t bufferSize
 
std::list< spi::LoggingEventPtr > buffer
 
unsigned long fLastId
 
bool fIsConnectionOpen
 

Detailed Description

Definition at line 98 of file MySQLAppender.h.

Member Function Documentation

void MySQLAppender::append ( const spi::LoggingEventPtr &  event)

Adds the event to the buffer. When full the buffer is flushed.

Definition at line 84 of file MySQLAppender.cxx.

void MySQLAppender::close ( )
virtual

Closes the appender, flushing the buffer first then closing the default connection if it is open.

Definition at line 181 of file MySQLAppender.cxx.

void MySQLAppender::closeConnection ( )
protectedvirtual

Override this to return the connection to a pool, or to clean up the resource.

The default behavior holds a single connection open until the appender is closed (typically when garbage collected).

Definition at line 134 of file MySQLAppender.cxx.

unsigned int MySQLAppender::execute ( const String &  sql)
protected

Override this to provide an alertnate method of getting connections (such as caching). One method to fix this is to open connections at the start of flushBuffer() and close them at the end. I use a connection pool outside of MySQLAppender which is accessed in an override of this method.

Definition at line 108 of file MySQLAppender.cxx.

void MySQLAppender::flushBuffer ( )

loops through the buffer of LoggingEvents, gets a sql string from getLogStatement() and sends it to execute(). Errors are sent to the errorHandler.

If a statement fails the LoggingEvent stays in the buffer!

— Task description

Definition at line 212 of file MySQLAppender.cxx.

MYSQL * MySQLAppender::getConnection ( )
protectedvirtual

Override this to link with your connection pooling system.

By default this creates a single connection which is held open until the object is garbage collected.

Definition at line 146 of file MySQLAppender.cxx.

String MySQLAppender::getLogStatement ( const spi::LoggingEventPtr &  event)
protected

By default getLogStatement sends the event to the required Layout object. The layout will format the given pattern into a workable SQL string.

Overriding this provides direct access to the LoggingEvent when constructing the logging statement.

Definition at line 94 of file MySQLAppender.cxx.

const String& log4cxx::db::MySQLAppender::getSql ( ) const
inline

Returns pre-formated statement eg: insert into LogTable (msg) values ("%m")

Definition at line 243 of file MySQLAppender.h.

virtual bool log4cxx::db::MySQLAppender::requiresLayout ( ) const
inlinevirtual

MySQLAppender requires a layout.

Definition at line 232 of file MySQLAppender.h.

void MySQLAppender::setOption ( const String &  option,
const String &  value 
)
virtual

Set options

Definition at line 53 of file MySQLAppender.cxx.

void MySQLAppender::setSql ( const String &  s)

Set pre-formated statement eg: insert into LogTable (msg) values ("%m")

Definition at line 333 of file MySQLAppender.cxx.

Member Data Documentation

std::list<spi::LoggingEventPtr> log4cxx::db::MySQLAppender::buffer
protected

ArrayList holding the buffer of Logging Events.

Definition at line 145 of file MySQLAppender.h.

size_t log4cxx::db::MySQLAppender::bufferSize
protected

size of LoggingEvent buffer before writting to the database. Default is 1.

Definition at line 140 of file MySQLAppender.h.

MYSQL* log4cxx::db::MySQLAppender::connection
protected

Connection used by default. The connection is opened the first time it is needed and then held open until the appender is closed (usually at garbage collection). This behavior is best modified by creating a sub-class and overriding the getConnection and closeConnection methods.

Definition at line 123 of file MySQLAppender.h.

String log4cxx::db::MySQLAppender::databasePassword
protected

User to use for default connection handling

Definition at line 114 of file MySQLAppender.h.

String log4cxx::db::MySQLAppender::databaseURL
protected

URL of the DB for default connection handling

Definition at line 104 of file MySQLAppender.h.

String log4cxx::db::MySQLAppender::databaseUser
protected

User to connect as for default connection handling

Definition at line 109 of file MySQLAppender.h.

String log4cxx::db::MySQLAppender::sqlStatement
protected

Stores the string given to the pattern layout for conversion into a SQL statement, eg: insert into LogTable (Thread, File, Message) values ("%t", "%F", "%m")

Be careful of quotes in your messages!

Also see PatternLayout.

Definition at line 134 of file MySQLAppender.h.


The documentation for this class was generated from the following files: