Forums Register Login

Log4j Wrapper

+Pie Number of slices to send: Send
Hi,
We are creating log4j wrapper for our application as follows.Will this create any threading issue..
public class LoggingUtil {
static Logger logger = Logger.getLogger(LoggingUtil.class);
public static void debug(Class<?> classNm,Object message)
{
if(logger.isDebugEnabled()){
logger.log(classNm.getName(), Level.DEBUG, message,null);}
}

}

Thanks and Regards
A.Raj
+Pie Number of slices to send: Send
It's thread safe, because it has no state. Any class that has no state would be fundamentally thread safe.

On a side note, why would you want to create such a wrapper, it does not offer any benefit over the usual logging API!
+Pie Number of slices to send: Send
@Arockia
Why do you think it will create any threding issue?
+Pie Number of slices to send: Send
 

Saifuddin Merchant wrote:It's thread safe, because it has no state. Any class that has no state would be fundamentally thread safe.

On a side note, why would you want to create such a wrapper, it does not offer any benefit over the usual logging API!




Thanks for the reply...The reason for this wrapper class is,we dont want to have 3rd libraray jars(com.apache.log4j) inside all over application codes and prefer to restrict to one wrapper class..so that in future if we decide to change log4j with any async implementation then the impact is only for the wrapper calss
+Pie Number of slices to send: Send
 

Niraj Jha wrote:@Arockia
Why do you think it will create any threding issue?


@Niraj :Thanks for the reply,the reason is this class is having static instance Logger variable..hence need to sure it will be thread safe..
+Pie Number of slices to send: Send
 

the reason is this class is having static instance Logger variable..hence need to sure it will be thread safe..


The Log4J docs say "Calling the getLogger method with the same name will always return a reference to the exact same logger object." so it doesn't matter if you have a static reference to the logger or get a new reference each time one of your wrapper methods are called, for a given logger name you will always use the same logger object.
+Pie Number of slices to send: Send
Drove my Chevy to the levee but the levee was dry. A wrung this tiny ad and it was still dry.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1724 times.
Similar Threads
Using Log4j efficiently
Access HttpSession from static methods
log4j vs system.out.Println()
Conditional Logging
Configure two log4j loggers in one application
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:40:00.