File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Open Source Projects and the fly likes Log4J help 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 "Log4J help" Watch "Log4J help" New topic

Log4J help

Anjali Naveen

Joined: Jun 28, 2005
Posts: 15
I have a wrapper around a log4J logger. Using pattern layout i print to console and a file. The problem im facing is in printing the method name, class name and line number. Since my l7dlog or log method calls are within the wrapper, the line number class and method name reflect the method inside the wrapper and not from where the log might have actually been logged. How do i work around this problem
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Moving to Other Open Source Projects...

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
banuchithra chithra

Joined: Oct 04, 2005
Posts: 3
Hi Anjali,
Hope you solved your problem by now. If not, you can refer to the following link.

But since this method of using %i is slow , you can use the following:

If you want to get the calling class, method and line number in case an exception occurred, it is easy. If you get the exception object in your wrapper method, you can use this :

// here thro is the throwable object

StackTraceElement[] sTrace = thro.getStackTrace();
String callingClass = sTrace[0].getClassName();
String callingMethod = sTrace[0].getMethodName();
int lineNumber = sTrace[0].getLineNumber();

Hope that helps

[ October 04, 2005: Message edited by: banuchithra chithra ]
I agree. Here's the link:
subject: Log4J help
jQuery in Action, 3rd edition