Store registration information in oracle database

I have currently implemented a java swing application. In this application, I used java.util.logging to enter a text file. But it’s hard to go through a text file because the file is very large.

So, I'm going to store the registration information in the oracle database (which I use for the application) and provide the swing interface to access this table. Therefore, I can search this table for specific logging levels such as INFO and SEVERE. Is there a way to do this using the java util package or using Log4j. Pls Help

+3
source share
3 answers

Take a look at these apps: org.apache.log4j.jdbc.JDBCAppenderor an improved version org.apache.log4j.jdbcplus.JDBCAppender.

+7
source

You can write your own Appender by expanding org.apache.log4j.AppenderSkeleton. You can configure it for several data stores and determine how to split LoggingEvent , where you can get individual information in the form of a line number, class name, message, confidence level, etc.

public class StorageBasedAppender
    extends AppenderSkeleton
{
    [...]

    @Override
    protected void append(LoggingEvent event)
    {
        // Write to your database or other storages
    }
}

You can improve this class by customizing it and more. If you don’t need specifics, for other issues, use the JDBCAppenderConfiguration . What can be easily configured

<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> 
0
source

JDBC Log4j Appender.

Tutorialspoint Apache Wiki

, , , .properties .xml.

0
source

Source: https://habr.com/ru/post/1781798/


All Articles