LogManager and Logging
Estimated time to read: 1 minute
Main.java
import java.util.logging.Level;
import java.util.logging.Logger;
// ...
public class App {
public static void main(String[] args) {
LoggingUtil.initLogManger();
final Logger LOGGER = Logger.getLogger(App.class.getSimpleName());
LOGGER.log(Level.INFO, "Starting Application");
// ...
}
}
LoggingUtil.java
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.LogManager;
public class LoggingUtil {
public static void initLogManger() {
try {
LogManager.getLogManager().readConfiguration(new FileInputStream("./src/main/resources/logging.properties"));
} catch (SecurityException e) {
System.out.println("Experienced a SecurityException! \n Halting!");
e.printStackTrace();
} catch (FileNotFoundException e) {
System.out.println("Experienced a FileNotFoundException! \n Halting!");
e.printStackTrace();
} catch (IOException e) {
System.out.println("Experienced an IOException! \n Halting!");
e.printStackTrace();
}
}
}