wood burning stoves 2.0*
The moose likes Other Open Source Projects and the fly likes How can i print this in log4j ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "How can i print this in log4j ?" Watch "How can i print this in log4j ?" New topic
Author

How can i print this in log4j ?

Engin Okucu
Ranch Hand

Joined: Feb 09, 2002
Posts: 174
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

Joined: Aug 02, 2004
Posts: 823
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

Joined: Aug 02, 2004
Posts: 823
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
If you're working with JDK 1.3, this may or may not be helpful.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Engin Okucu
Ranch Hand

Joined: Feb 09, 2002
Posts: 174
Thanks everybody for reply.
Jules i will choose for your first advice. It's the most easy way to me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can i print this in log4j ?