Reputation: 2848
I have currently implemented a java swing application. In that application I have used java.util.logging to log things in to a text file. But It is difficult to go through the text file since the file is very big.
So I'm thinking to store logging information in to a oracle database(Which i am using for the application) and provide swing interface to access that table. So I will be able search that table for certain logging levels like INFO and SEVERE. Is there way to do that using java util package or using Log4j. Pls help
Upvotes: 3
Views: 6776
Reputation: 5963
You can make use of a JDBC Log4j Appender.
Check out Tutorialspoint or Apache Wiki
You might need to change your configuration accordingly whether you use .properties or .xml.
Upvotes: 0
Reputation: 48265
Take a look at these appenders: org.apache.log4j.jdbc.JDBCAppender
or an improved version org.apache.log4j.jdbcplus.JDBCAppender
.
Upvotes: 8
Reputation: 11435
You could write your own Appender by extending the org.apache.log4j.AppenderSkeleton
. You can make him configurable for several data storages and define how to split up the LoggingEvent where you can get the seperated informations as line-number, class-name, message, logger-severity etc.
public class StorageBasedAppender
extends AppenderSkeleton
{
[...]
@Override
protected void append(LoggingEvent event)
{
// Write to your database or other storages
}
}
You could enhance this class by making it configurable and more. If you don't need somewhat specific, regardings to the other questions make use of the JDBCAppenderConfiguration. Which can be configured easily
<appender name="jdbcAppender" class="org.apache.log4j.jdbc.JDBCAppender">
<param name="URL" value="jdbc:oracle:thin:@sd1.hbs.edu:1521:sc1" />
<param name="Driver" value="oracle.jdbc.driver.OracleDriver" />
<param name="User" value="user" />
<param name="Password" value="password" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="INSERT INTO LOGGING_SAMPLES_TEST
(log_date, log_level, location, message)
VALUES ( '%d{ISO8601}','%p', '%C;%L', '%m' )"
/>
</layout>
</appender>
Upvotes: 0