This week's book giveaway is in the Agile forum.
We're giving away four copies of The Software Craftsman and have Sandro Mancuso on-line!
See this thread for details.
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 The Software Craftsman this week in the Agile 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
Rancher

Joined: Mar 22, 2005
Posts: 42954
    
  73
"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: 14667
    
  25

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to get java class name and method name and print it from the method