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
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 35224
    
    7
"new Exception().getStackTrace()" gives you the stack trace information which contains the class and method name.


Android appsImageJ pluginsJava web charts
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12907
    
    3

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to get java class name and method name and print it from the method
 
Similar Threads
Print calling method and class name
Printing number of records from a ResultSet
Log4J help
Printing method name using log4j
how does java implement all this ?