Logging in Java with the JDK
For some time the JDK has had internal logging, if it is already there why use some other, probably bloated and inefficient, framework?
One problem for me was customisation of the logging infrastructure, I want to log but why do I need to pass a command line VM parameter? You don't have to:
try (FileInputStream configFile = new FileInputStream("/path/to/app.properties")) { // you could also load from classpath using .getResourceAsStream(); LogManager.getLogManager().readConfiguration(configFile); } catch (IOException ex) { System.out.println("WARNING: Could not open configuration file"); System.out.println("WARNING: Logging not configured (console output only)"); } log.info("starting normal logged services.");
The above uses the Java 7 Automatic Resource try
syntax, mainly because I think it is quite cool, you will need to re-write for
Java 1.4, 1.5 and 1.6... but maybe you should also think about upgrading your VM?