aspose file tools*
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
Author

Log4J help

Anjali Naveen
Greenhorn

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
author
Sheriff

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
Greenhorn

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

http://www.coderanch.com/t/62680/open-source/make-log-print-out-class

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

Banu
[ October 04, 2005: Message edited by: banuchithra chithra ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Log4J help