Hi, I would like to improve the answer with this piece of code.
import java.io.IOException; import java.util.logging.FileHandler; import java.util.logging.Level; import java.util.logging.Logger; import java.util.logging.SimpleFormatter; public class MyTestLogger { public static void main(String[] args) throws SecurityException, IOException { FileHandler fileTxt = new FileHandler("eLog.txt", true); SimpleFormatter formatter = new SimpleFormatter(); fileTxt.setFormatter(formatter); Logger LOGGER = Logger.getLogger(MyTestLogger.class.getName()); LOGGER.addHandler(fileTxt); LOGGER.setLevel(Level.SEVERE); LOGGER.severe("This is a serious problem !"); } }
source share