*
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
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: 41107
    
  45
"new Exception().getStackTrace()" gives you the stack trace information which contains the class and method name.


Ping & DNS - my free Android networking tools app
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
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
 
Similar Threads
Print calling method and class name
Log4J help
Printing method name using log4j
Printing number of records from a ResultSet
how does java implement all this ?