Thought of documenting this for my own reference, hope this will help. I am also planing to make a knowledge base article out of it to be posted in WSO2 Oxygen Tank.
As you may know, if your are familiar with Log4j, that the logs created with it, can be stored in a database instead of a file. In order to do that you need to add few configuration values to the log4j.properties file.
In-terms of a WSO2 Carbon based server this properties file resides in CARBON_HOME/lib directory. before adding these configurations there are few steps to visit.
[1] Create database {LOG_DB}
[2] Create the log table {LOGGING} with the following fields
create table LOGGING ( id decimal NOT NULL, prio varchar(15), cat varchar(255), thread varchar(30), msg varchar(255), layout_msg varchar(255), throwable varchar(2000), the_timestamp timestamp);
[3] Create a user and assign to the DB
{user: logger / pwd: logger}
[4] Copy jdbcappender.jar to {CARBON_HOME}/lib and {CARBON_HOME}/repository/components/lib along with the database driver
{jdbcappender.jar can be found at http://www.dankomannhaupt.de/projects/jdbcappender/lib/jdbcappender.jar}
Thats it. All preconditions are set, Now open up the log4j.properties file and add the following appender settings to the end.
#log to db appender log4j.appender.DB_APPENDER=org.apache.log4j.jdbcplus.JDBCAppender log4j.appender.DB_APPENDER.url=jdbc:mysql://localhost:3306/LOG_DB log4j.appender.DB_APPENDER.dbclass=com.mysql.jdbc.Driver log4j.appender.DB_APPENDER.username=logger log4j.appender.DB_APPENDER.password=logger log4j.appender.DB_APPENDER.sql=INSERT INTO LOGGING (id, prio, cat, thread, msg, layout_msg, throwable, the_timestamp) VALUES (@INC@, '@PRIO@', '@CAT@', '@THREAD@', '@MSG@', '@LAYOUT:1@', '@THROWABLE@', '@TIMESTAMP@') log4j.appender.DB_APPENDER.layout=org.apache.log4j.PatternLayout
Scroll to log4j.rootLogger and add the appender to the list,
log4j.rootLogger=ERROR, CARBON_CONSOLE, CARBON_LOGFILE, CARBON_MEMORY, CARBON_SYS_LOG, DB_APPENDER