File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Log4J help

 
Anjali Naveen
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Other Open Source Projects...
 
banuchithra chithra
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic