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 am using this property file to setup log4j in Spring: log4j.appender.EMAIL=org.apache.log4j.net.SMTPAppender log4j.appender.EMAIL.filter=org.apache.log4j.varia.LevelRangeFilter log4j.appender.EMAIL.filter.levelMin=FATAL
I have been using com.sun.org.apache.xpath.internal.XPathAPI for some time and it seems to work ok.
In Java, we're using the following package to programmatically create excel documents: org.apache.poi.hssf If
I'm interested in using a Reed-Solomon error correction [ http://en.wikipedia.org/wiki/Reed%E2%80%93Solomon_error_correction as a reference] to
I have this log4j configuration in my grails config.groovy log4j = { error 'org.codehaus.groovy.grails.web.servlet',
I am using log4j to do my logging. I lately added a library (Connection
My java application uses log4j for logging. Using ant the project builds successfully, but
I'm using org.w3c XML API to open an existing XML file. I'm removing some
I am using OpenOffice.org for most of my not so very frequent Office Suite
How do I import a CSV file using OpenOffice.org APIs? I want to do

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.