Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can i print this in log4j ?

 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class that contains debug(Object obj),warn(Object obj),...
I want to print the class name that called these methods.
It always prints the name of the class that contains debug, warn,info,... methods and not the name of the class that calls these methods.

thanks.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The only way I can see of doing that is to pass the calling class (or class name) into your utility methods.

My advice would be not to use wrapper methods like these if you can possibly do without them. If you're convinced that you need to wrap the log4j calls you might be better off extending the Logger class and doing it that way. Note that I haven't looked into the practicality of doing that at all.

Jules
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, you learn something new every day and here is my new thing for today:

Note that if performance is a key factor in your app and logging stays on in the production environment you will probably want to avoid this amount of processing on each logging call.

Jules
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're working with JDK 1.3, this may or may not be helpful.
 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everybody for reply.
Jules i will choose for your first advice. It's the most easy way to me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic