aspose file tools*
The moose likes Beginning Java and the fly likes How to get java class name and method name and print it from the method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to get java class name and method name and print it from the method " Watch "How to get java class name and method name and print it from the method " New topic
Author

How to get java class name and method name and print it from the method

Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
Hello all
Im using custom logger (simple prints)
And I like to print the class name and the method from witch the log print has bean executed.
How can I do it ?
p.s
I can't use log4j in my project .
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42908
    
  69
"new Exception().getStackTrace()" gives you the stack trace information which contains the class and method name.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14420
    
  23

You can't use Log4J, but since Log4J is open source you could still have a look at the source code of Log4J to see how it's done there.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
bart zagers
Ranch Hand

Joined: Feb 05, 2003
Posts: 234
This thread recently discussed the same subject.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get java class name and method name and print it from the method