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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:30:23+00:00 2026-06-10T11:30:23+00:00

I am very new to log4j. I do not want to show exception stack

  • 0

I am very new to log4j. I do not want to show exception stack trace in my log file such as

java.lang.IllegalArgumentException: nodeRef is a mandatory parameter
at org.alfresco.util.ParameterCheck.mandatory(ParameterCheck.java:42)

These exceptions are written directly to console by using e.printStackTrace() like that

try {
    // something
} catch(Exception e) {
    StringWriter stack = new StringWriter();
    e.printStackTrace(new PrintWriter(stack));
    logger.debug("Caught exception; decorating with appropriate status template : " + stack.toString());
}

I am now customizing a Open Source project, not writing all my programs by myself.
So it is impossible to remove e.printStackTrace(); in all of java files.

As far as I know, log which are printed by log4j with logger can be configured by using log4j error level such as info, debug, warn.But how about writing directly to console or file?

How can I configure log4j not to print only exception stacktrace but show other information? Is there a way to solve it out?

  • 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-06-10T11:30:24+00:00Added an answer on June 10, 2026 at 11:30 am

    The code

    StringWriter stack = new StringWriter();
    e.printStackTrace(new PrintWriter(stack));
    logger.debug("Caught exception; decorating with appropriate status template : " + stack.toString());
    

    is just an example of plain wrong usage of the Log4j API. But, if you are stuck with it, there will be nothing for you to do except raise the log level above debug and leave out the entire message.

    There may possibly be a way to truncate all log messages, which would somewhat alleviate your problem.

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

Sidebar

Related Questions

Very new to this, and I have no idea where to start. I want
Still very new to Rails. How do I call my method in calltwitter.rb file
I am very new to Bamboo. I have got a html file generated using
Im very new to C programing, but have limited experience with Python, Java, and
Im very new to acceleo , for text generation(for java language) i'm using ecore
Very new to jQuery, if dupe question sorry at this point not even sure
Very new to javascript here folks, so forgive the newbie question. I want to
Im very new in php and try to use cookie but it is not
The current project in wherein I'm working creates a log file using the log4j
Very new to Java and Swing, and I have been playing with a swing

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.