• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Define a logger for a specific call hierarchy

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Currently i am working on log4j stuff for my application. I have a specific requirement of logging. I need to define a logger for a specific call hierarchy.
Meaning all the log messages of a specific call hierarchy should go to a specific appeneder.

Example

AddFormAction(method1) ---------------
|
|
|
EditFormAction(method2) --------------|---------- FormBusinessObject(method4) ------------- FormDAOObject(method5)
|
|
|
|
DeleteFormAction(method3)-------------|


I want to define a logger for a specific call hierarchy 1 - 4 -5. These messages should goto addform.log.

I don't want the messages from 2-4-5 or 3-4-5 call hierarchies to go to addform.log.

Hope iam clear on my requirement. Any help is highly appreciated. Thanks all in advance for your replies.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure this is possible if you're using typical logger declarations (named by Foo.class etc.) because there's no way to differentiate which "flow" a method call is participating in.

The only simple options I can think of quickly is to create new, additional loggers, each having the same name, and track application state through some mechanism, and track state machine progress throughout the app, and use that to determine which logger should be used. Depending on your application, it *might* be possible to encapsulate *all* of that logic using AOP, which might actually be a pretty slick solution if doable.
 
Venkata Sirish
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply. This is a stand alone application so i cannot make use of any HTTP scopes like session, application.

Please let me know if it can be achieved in any other way.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Um... my response didn't say anything about a web application or web app scopes--any Java program can store state in a globally-accessible location, either using a singleton, an in-memory DB, or whatever. Any solution would work, and could be used either directly by the app (means modifying source), or via AOP (no source modification, but minor "magic" if you're not aware how it's being done, which can cause maintenance issues).

What else do you want to know?
 
reply
    Bookmark Topic Watch Topic
  • New Topic