Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 993729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:28:11+00:00 2026-05-16T06:28:11+00:00

Re-thinked IDEA! So, I’ve been thinking over the weekend and couldn’t let this one

  • 0

Re-thinked IDEA!

So, I’ve been thinking over the weekend and couldn’t let this one go. I’ve decided to re-try the idea of getting log4j to work.

I’ve been doing some coding and think I got it to work. Except, I do not really understand how to insert into the logger. I’ve created an JDBC-appender and the SQL looks like this:

    <layout class="org.apache.log4j.PatternLayout"> 
        <param name="ConversionPattern" 
          value="INSERT INTO audit (timestamp, user, operation, source, resourceRange, additionalInfo) VALUES ('%d{yyyy-MM-dd H:mm:s,SSS}','%m', '%m', '%m', '%m', '%m')"
        /> 
    </layout> 

Is this correct? All values has the VARCHAR datatype.

But, the real question for me is how do I log this in the Java-code?
Can’t really understand what values to insert to get the correct values to insert the database.

 logger.log(?);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:28:12+00:00Added an answer on May 16, 2026 at 6:28 am

    Just to make sure; you can not use log4j and use JDBCAppender or DBAppender?
    ( Log to a database using log4j )

    EDIT:

    My suggestion would be to have a named appender that logs to the database.

    By turning off additivity (log4j.additivity.database=false), it won’t “push” log statements to the root logger, keeping that data out of the default log file/console. The named logger can be retrieved by Logger.getLogger("database"); from different places in the source code.

    EDIT 2:

    I think it would’ve been better to let the original question stand, and ask a new one, but here goes. 🙂

    The appender must contain information about the database connection, either as a reference to the connection: <param name="connector" value="name.of.existing.ConnectionHandler" /> or by specifying url, username and password.

    Setting up the logger, the name is the important bit for getting the logger. By setting the loggers additivity to fale, you stop it from adding this logging to the default logger specified by <root> in the config:

    <appender name="JDBC" class="org.apache.log4j.jdbcplus.JDBCAppender">
        [...]
    </appender>
    <logger name="myLogger" additivity="false">
        <appender-ref ref="JDBC"/>
        [...]
    </logger>
    

    Now you can reference the logger in java code with:

    private static final Logger usageLog = Logger.getLog("myLogger");
    

    from any java file. Then you use the logger like always, with usageLog.debug("Debug message"); or something.

    EDIT 3:

    See PatternLayout javaDoc for which flags to use in the ConversionPattern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using a SAX parser for a while now to get data
Because of the changes I have done to my post I have thinked to
I think the solution to my problem is very easy, but i couldn't fint
I have an architectural question for you :) In my new project i'm developing
I have an issue here. Suppose you have a business periodical task, for instance
I have multiple NET.TCP services that provide access to my apps bussiness logic layer.
maybe I'm missing something. I believed that WPF vector-based Drawings (like DrawingGroup, DrawingGeometry, etc.)
I want to create a fixed layout that displays some images. for example, a
Apart from main thread, I've ThinkerThread object _thinker whose finished() signal is connected to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.