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

  • SEARCH
  • Home
  • 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 org.apache.log4j.Logger for logging and I am developing a jsp just for
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'm using org.apache.tools.ant.listener.Log4jListener to manage logging with my ant script. The ant script is
I want to add logging to an application I am developing, using apache log4j.
while using Perf4j together with Log4j I get the following exception: log4j:ERROR Error occured
I've created a appender of the type NTEventLogAppender like this: log4j.appender.EVA=org.apache.log4j.nt.NTEventLogAppender #log4j.appender.EVA.log=TestLog log4j.appender.EVA.layout=org.apache.log4j.PatternLayout log4j.appender.EVA.source=TestSource
I am using org.apache.commons.validator.routines.DateValidator to validate a date with a simple date pattern dd/mm/yyyy
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 just started using the new POI 3.6 http://poi.apache.org XSSF which was released in

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.