• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Struts 2 - Logging Interceptor for all the classes

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to implement logging interceptor for all my classes that are invoked when user request is processed by the server.

The framework we have in place is as follows:

Action -> Service -> DAO -> Adapter -> 3rd Party API invocation.

When using struts interceptors, I implemented the logging. However, it only intercepts the action classes and prints the entry/exit of action classes. I want to extend this to ensure entry/exit of all methods are printed so that it helps me in debugging the code on production. However, it seems by default struts doesn't offer this.

Has anyone implemented such requirement ? If yes please share your learning.

Code snippet



 
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
240 posts and you still don't UseCodeTags? For shame!

I want to extend this to ensure entry/exit of all methods are printed so that it helps me in debugging the code on production. However, it seems by default struts doesn't offer this.



I think this is a limitation on Java, not Struts. There may be some languages where you can enforce every method calling some other method, but Java is not one of them.
 
Saurabh Agrawal
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that is a java limitation. Frameworks like sprint allow using point cut strategy to intercept each class and it's corresponding methods to print log messages.

I have used it in my past project using Spring. I wanted to see if we can do a similar thing in struts2 as well.

Saurabh
 
Ranch Hand
Posts: 51
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saurabh,

I agree with you on Spring part. It allows method level interception(before-after).
If you want method level interception for various methods, you might have to leverage regular expressions withing AOP.
I haven't implemented these though.
However, what you're looking for; i have not seen that in Struts.
 
Joe Ess
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Saurabh Agrawal wrote:I don't think that is a java limitation. Frameworks like sprint allow using point cut strategy to intercept each class and it's corresponding methods to print log messages.



I was referring to built-in functionality. For certain, if you want jump through some hoops with AOP, you can cobble something together. You can use Spring with Struts, but I don't know if that gets you any closer to your goal.
I just start each "interesting" method with a log statement and use log levels to throttle the amount of information that is logged.
 
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic