Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"new Exception().getStackTrace()" gives you the stack trace information which contains the class and method name.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15367
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This thread recently discussed the same subject.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic