Invoke the shutdown() method of your custom logger in finally{} block of your code
Logger.getLogger(MyClassNameHere.class.getName());
This will not return your CustomLogging instance. Your initialize() should return logger which your Code must use for logging.
Example:
public class CustomLogging
{
static private FileHandler txtFileHandle;
static private SimpleFormatter formatterTxt;
static public Logger getLogger(Class loggerClass) throws IOException
{
//Global logger configuration
Logger logger = Logger.getLogger(loggerClass);
logger.setLevel(Level.INFO);
txtFileHandle = new FileHandler("Logging.txt");
formatterTxt = new SimpleFormatter();
txtFileHandle.setFormatter(formatterTxt);
logger.addHandler(txtFileHandle);
return logger;
}
static public void shutdown() throws IOException
{
txtFileHandle.close();
}
}
Use it like this:
CustomLogging logger = CustomLogging.getLogger(MyClassNameHere.class);
try{
logger.info("print in log");
}finally{
logger.shutdown();
}