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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:53:09+00:00 2026-05-14T16:53:09+00:00

I have recently inherited a J2EE Struts web app that was written back in

  • 0

I have recently inherited a J2EE Struts web app that was written back in 2002. There is no logging in the application other than the odd System.out.println().
I have added log4j logging so that I can write out some info to the console, but I’m concerned on how best to approach this. Any suggestions, tips, best practices would be welcome as I don’t want to spend too much time adding logging to every method or class (or trying to find what places where logging would be best – ie. bad code blocks/defects).
My current approach is to just add some logging to the few classes that I have been looking at to understand the code, but are there a few key places where I can add logging to maximize my use of adding log4j?

Edit:
Progress update:
I extended the Struts (v.1) ExceptionHandler and configured the struts-config.xml to use my CustomExceptionHandler instead of the Struts version. Then by overriding the execute() method, I added some logic to log the exception using log4j. See below:

public class CustomExceptionHandler extends ExceptionHandler {

 static Logger logger = Logger.getLogger(CustomExceptionHandler.class);

 public ActionForward execute(Exception ex, ExceptionConfig ae, ActionMapping mapping, ActionForm formInstance, HttpServletRequest request, HttpServletResponse response) throws ServletException {
  logException(ex);
  return super.execute(ex, ae, mapping, formInstance, request, response);
 }

 private void logException(Throwable thr) {
   // Add code here to log the exception appropiately
   // i.e. logger.error("Exception is: " + ex.getMessage());
}

The struts-config.xml file had to be updated as well:

<global-exceptions>
<exception key="" type="java.lang.Throwable"
handler="com.mycompany.CustomExceptionHandler" />
</global-exceptions>

Now I can be sure that I will always appropiately log any exceptions.
For the exceptions that were getting eaten, I wrap them in unchecked exceptions so that they make it to the top:

} catch (Exception e) {
//nothing here
}

Changed to:

} catch (Exception e) {
 throw new RuntimeException(e);
}
  • 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-14T16:53:10+00:00Added an answer on May 14, 2026 at 4:53 pm

    The most important thing is, I would set up a Struts exception handler in the struts-config.xml to catch everything that was thrown from the actions and log it. Then I’d check all the exception handling to see what exceptions are getting eaten, written to stdout, or otherwise not making it into the log, and make changes so that every exception that can’t be usefully handled gets propagated (wrapped in unchecked exceptions if necessary) so that it makes it to the exception handler.

    Besides that, I’d do like you describe, adding logging to the parts where it is directly helpful. As long as exceptions are getting thrown and making their way to the exception handler there shouldn’t be much more to do.

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

Sidebar

Related Questions

I have recently written an application(vb.net) that stores and allows searching for old council
I recently inherited an e-commerce app (Java/Struts) that I'm porting to Rails. The thing
I have recently inherited a website written in Classic ASP, and am currently trying
I recently inherited a VBA macro that needs to have validation logic added to
I have recently inherited an ASP.Net app using Linq2SQL. Currently, it has its DataContext
I have recently installed .net 3.5 SP1. When I deployed a compiled web site
I have recently upgraded some of my web applications to ASP.NET 3.5 by installing
I recently inherited an iPhone app. The original developer did not understand memory management
I recently inherited a Ubuntu Hardy box that acts rather funky out-of-the-box. The first
I recently inherited a simple PHP application built on Piwi ( http://www.piwiframework.de/default.html ). Has

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.