|
Apache Log4cxx
Version 2.0.0
|
The DBAppender lets you log messages to a database. More...
#include <dbappender.h>
Public Member Functions | |
| DBAppender () | |
| virtual | ~DBAppender () |
| void | setOption (const LogString &option, const LogString &value) override |
Override this method to set option to value. | |
| void | activateOptions () override |
| Activate the specified options. | |
| void | append (const spi::LoggingEventPtr &event) override |
| Adds the event to the buffer. | |
| void | setSql (const LogString &s) |
| Set pre-formated statement eg: insert into LogTable (msg) values (?). | |
| const LogString & | getSql () const |
| Returns pre-formated statement eg: insert into LogTable (msg) values (?). | |
| Public Member Functions inherited from log4cxx::AppenderSkeleton | |
| AppenderSkeleton (const LayoutPtr &layout={}) | |
| virtual | ~AppenderSkeleton () |
| void | addFilter (const spi::FilterPtr &newFilter) override |
Add newFilter to end of the spi::Filter chain. | |
| void | clearFilters () override |
| Clear the spi::Filter chain. | |
| void | close () override |
| Release any resources allocated within the appender such as file handles, network connections, etc. | |
| const spi::ErrorHandlerPtr | getErrorHandler () const |
| The currently set spi::ErrorHandler for this Appender. | |
| spi::FilterPtr | getFilter () const override |
| The first spi::Filter in the filter chain for this Appender. | |
| const spi::FilterPtr | getFirstFilter () const |
| The first spi::Filter in the filter chain for this Appender. | |
| LayoutPtr | getLayout () const override |
| The currently set Layout for this appender. | |
| LogString | getName () const override |
| The name of this Appender. | |
| const LevelPtr | getThreshold () const |
| This appender's current threshold level. | |
| bool | isAsSevereAsThreshold (const LevelPtr &level) const |
Is level greater than or equal to this appender's threshold? | |
| void | doAppend (const spi::LoggingEventPtr &event) override |
| Call doAppendImpl after acquiring a lock that prevents other threads from concurrently executing doAppendImpl. | |
| void | setErrorHandler (const spi::ErrorHandlerPtr &newValue) |
Use newValue as the spi::ErrorHandler for this Appender. | |
| void | setLayout (const LayoutPtr &newValue) override |
Use newValue as the layout for this appender. | |
| void | setName (const LogString &newValue) override |
Use newValue for the name of this Appender. | |
| void | setThreshold (const LevelPtr &newValue) |
Use newValue as this appender's threshold level. | |
| void | activateOptions (helpers::Pool &) |
| Public Member Functions inherited from log4cxx::Appender | |
| virtual | ~Appender () |
| void | doAppend (const spi::LoggingEventPtr &event, helpers::Pool &pool) |
| virtual bool | requiresLayout () const |
| Public Member Functions inherited from log4cxx::spi::OptionHandler | |
| virtual | ~OptionHandler () |
| void | activateOptions (helpers::Pool &) |
| Public Member Functions inherited from log4cxx::helpers::Object | |
| virtual | ~Object () |
| virtual const helpers::Class & | getClass () const =0 |
| virtual bool | instanceof (const Class &clazz) const =0 |
| virtual const void * | cast (const Class &clazz) const =0 |
Additional Inherited Members | |
| Protected Member Functions inherited from log4cxx::AppenderSkeleton | |
| AppenderSkeleton (LOG4CXX_PRIVATE_PTR(AppenderSkeletonPrivate) priv) | |
| void | doAppendImpl (const spi::LoggingEventPtr &event) |
Call the AppenderSkeleton::append method if the level of event is not lower than this appender's threshold and no attached spi::Filter indicates event is rejected. | |
| bool | isAccepted (const spi::LoggingEventPtr &event) const |
Does no attached filter deny event or does an attached filter accept event? | |
The DBAppender lets you log messages to a database.
This utilizes the APR's database support in order to provide a single way of logging to multiple databases, not just ODBC as the ODBCAppender does.
The following SQL script is an example of how you may make a table that stores log messages:
Once you have defined the table, you must define the order in which the columns are formatted when they are inserted along with the insert statement.
Using APR, the following insert statement can be used to insert log statements: INSERT INTO logs (logger, time, level, file, line_number, message) VALUES (%s, %pDa, %s, %s, %d, %s) The values to insert must be formatted appropriately and in the correct order. In order to do this, the parameter ColumnMapping must be specified as many times as there are columns to insert.
The following table shows the conversion specifiers. These are effectively the same as the conversion patterns provided by PatternLayout but with more descriptive names:
| Conversion Specifier | Effect |
|---|---|
| logger | The name of the logger(e.g. com.foo.bar) |
| class | The class that the log message was in |
| time | The time of the log message |
| shortfilename | The short filename where the log message is from |
| fullfilename | The full filename where the log mesasge is from |
| location | The location of the log message |
| line | The line where the log message appears |
| message | The log message |
| method | The method where the message was logged |
| level | The level of the log message |
| thread | The thread where this message was logged |
| threadname | The name of the thread that logged the message |
| ndc | The NDC(nested diagnostic context) of the log |
Other parameters that are important:
| Parameter name | Usage |
|---|---|
| DriverName | The name of the database driver to load(ex: odbc, sqlite3) |
| DriverParams | A string of parameters to pass to the driver. This is database-specific |
| DatabaseName | The name of the database to use when connecting to the server |
The following code shows how you might connect to an ODBC data source and insert the log messages:
A similar configuration can be used for SQLite:
| log4cxx::db::DBAppender::DBAppender | ( | ) |
|
virtual |
|
overridevirtual |
Activate the specified options.
Reimplemented from log4cxx::AppenderSkeleton.
|
overridevirtual |
Adds the event to the buffer.
When full the buffer is flushed.
Implements log4cxx::AppenderSkeleton.
| const LogString & log4cxx::db::DBAppender::getSql | ( | ) | const |
Returns pre-formated statement eg: insert into LogTable (msg) values (?).
|
overridevirtual |
Override this method to set option to value.
| Supported options | Supported values | Default value |
|---|---|---|
| DriverName | {any} | - |
| DriverParams | {any} | - |
| DatabaseName | {any} | - |
| SQL | {any} | - |
| ColumnMapping | (^) | - |
(^) One value for each '%' character in the SQL value.
Reimplemented from log4cxx::AppenderSkeleton.
| void log4cxx::db::DBAppender::setSql | ( | const LogString & | s | ) |
Set pre-formated statement eg: insert into LogTable (msg) values (?).