aspose file tools*
The moose likes Other Open Source Projects and the fly likes Define a logger for a specific call hierarchy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Define a logger for a specific call hierarchy" Watch "Define a logger for a specific call hierarchy" New topic
Author

Define a logger for a specific call hierarchy

Venkata Sirish
Ranch Hand

Joined: Apr 09, 2007
Posts: 112
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.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Apr 09, 2007
Posts: 112
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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Define a logger for a specific call hierarchy