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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:02:56+00:00 2026-05-30T02:02:56+00:00

I have some legacy code where there are lot of e.printStackTrace() , those are

  • 0

I have some legacy code where there are lot of e.printStackTrace(), those are not printed in log4j file for obvious reasons. The latest code does have log.error("Exception occured in class::method",e);. Is there a standard way of logging those legacy e.printStackTrace() in log4j?

Here is my log4j.properties. I am setting up the property file/log file name within the code

PropertyConfigurator.configure("log4j.properties");
setLog4jFile("log.txt");

private static void setLog4jFile(String logFileName) {
        try {
            Logger rootLogger = Logger.getRootLogger();
            RollingFileAppender appender = new RollingFileAppender(new PatternLayout("%p %t %c - %m%n"), logFileName, false);
            appender.setMaxFileSize("10000KB");
            appender.setMaxBackupIndex(10);
            rootLogger.addAppender(appender);
        }catch (Exception e)    {
            e.printStackTrace();
        }
}

log4j.properties

log4j.rootCategory=info, stdout  
log4j.appender.stdout=org.apache.log4j.ConsoleAppender  
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout  
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F%L) - %m%n  
  • 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-30T02:02:57+00:00Added an answer on May 30, 2026 at 2:02 am

    You can redirect the standard System.err to log4j.

    This question and its answers should do the trick:

    log4j redirect stdout to DailyRollingFileAppender

    If possible though, I would still recommend to rewrite the printStacktrace‘s into log statements.

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

Sidebar

Related Questions

Today, I have seen some legacy code. In the destructor there is a statement
We have some legacy code that compiles in Delphi 6. There are plans to
I have some legacy code that was writing to a NITF file to display
I have some (legacy embedded c) code which produces a .csv file by means
I have some legacy code I'm maintaining and there's a SQL query in there
We have some legacy code that needs to identify in the Page_Load which event
I have some legacy code that was used to monitor my applications cpu,memory etc
I have some legacy C code that I recently compiled on Linux. On the
Presently I have a some legacy code, which generates the op code. If the
We have some legacy ASP.NET code that detects if a request is secure, and

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.