In my application I have written my own Logging utility using Java.Util.Logging
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.SimpleFormatter;
public class Logger {
public final static String PROPERTIES_FILE = "Logger.properties";
private static java.util.logging.Logger logger = null;
private static void initialize() {
try {
logger = java.util.logging.Logger.getLogger(Logger.class.getName());
FileHandler fh = new FileHandler("D:\\MyLogFile.log", true);
logger.addHandler(fh);
logger.setLevel(Level.ALL);
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);
logger.log(Level.INFO, "Test Message Logged");
}
catch (IOException e) {
System.out.println("Warning: Unable to read properties file " +
PROPERTIES_FILE );
}
}
public static synchronized java.util.logging.Logger getLogger(String name)
{
if(logger==null)
{
Logger.initialize();
}
logger.getLogger(name);
return logger;
}
}
Do I need to use Synchronization for getLogger method? Please give your comments. (This code is running in Multi-threaded environment)