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 6172459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:23:46+00:00 2026-05-23T23:23:46+00:00

Using org.apache.log4j.jdbc.JDBCAppender , how can I get stracktraces logged with warn and error into

  • 0

Using org.apache.log4j.jdbc.JDBCAppender, how can I get stracktraces logged with warn and error into the PatternLayout.

I’m logging like

logger.warn("warning description", e);
logger.error("error description", e);

I get the String descriptions into the table, but the Throwable’s stacktrace is now where. Is there another parameter that I can access via the PatternLayout. Currently I am using

"INSERT INTO app_logs (app, log_date, log_level, location, loc, message) VALUES ('my-apps-name', '%d{ISO8601}','%p', '%C.java', '%C{1}.java:%L', '%m')" 

into a table

TABLE `app_logs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `app` varchar(255) DEFAULT NULL,
  `log_date` varchar(255) DEFAULT NULL,
  `log_level` varchar(255) DEFAULT NULL,
  `location` varchar(255) DEFAULT NULL,
  `loc` varchar(255) DEFAULT NULL,
  `message` text, 
  PRIMARY KEY (`id`)
)
  • 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-23T23:23:46+00:00Added an answer on May 23, 2026 at 11:23 pm

    I found the solution.

    Replace the PatternLayout class with the EnhancedPatternLayout class.

    org.apache.log4j.EnhancedPatternLayout

    You’ll also need to include the apache-log4j-extra dependency

    Or include it in your pom:

    <dependency>
      <groupId>log4j</groupId>
      <artifactId>apache-log4j-extras</artifactId>
      <version>1.1</version>
    </dependency>
    

    You now have access to %throwable

    %throwable{short} or %throwable{1} will output the first line of stack
    trace. throwable{none} or throwable{0} will suppress the stack trace.
    %throwable{n} will output n lines of stack trace if a positive integer
    or omit the last -n lines if a negative integer.

    I added to my table,

    TABLE `app_logs` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `app` varchar(255) DEFAULT NULL,
      `log_date` varchar(255) DEFAULT NULL,
      `log_level` varchar(255) DEFAULT NULL,
      `location` varchar(255) DEFAULT NULL,
      `loc` varchar(255) DEFAULT NULL,
      `message` text,
      `throwable` text,
      `stacktrace` text,
      PRIMARY KEY (`id`)
    )
    

    And updated my pattern to populate these columns.

    "INSERT INTO app_logs (app, log_date, log_level, location, loc, message, throwable, stacktrace) VALUES ('my-apps-name', '%d{ISO8601}','%p', '%C.java', '%C{1}.java:%L', '%m', '%throwable{short}', '%throwable{100}')"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot get grails log4j logging to work in Tomcat6. I previously thought the
How do I configure jetty to use use log4j? I'm already using log4j in
I am using Spring & Hibernate in my application and I want to set
I'm using Ivy for project dependency management and it's been working well aside from
I am using Weblogic 116, Ejb3.0 , quartz-all 1.8.5. I have issues with quartz
I'm having this wierd issue with my log4JAppender. Im using a dailyRollingFileAppender and the
This is a standalone java application. I am using the configuration file below and
If I have a synchronized method and two threads are waiting to enter it
I need to force my Java application to run with a single instance. I

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.