Skip to content

Instantly share code, notes, and snippets.

Created September 28, 2016 18:21
Show Gist options
  • Save anonymous/108bfaffc17ab1016369b1a2e46fa067 to your computer and use it in GitHub Desktop.
Save anonymous/108bfaffc17ab1016369b1a2e46fa067 to your computer and use it in GitHub Desktop.
package org.stepic.java.module4.logdemo;
import java.util.logging.*;
import java.util.Arrays;
/**
* Created by vitaly on 28/09/16.
*/
public class LogDemo {
private static final Logger LOGGER = Logger.getLogger(LogDemo.class.getName());
public static void main(String[] args) {
// default logging level INFO, all finer events will be ignored
// default level could be redefined in .properties config file
LOGGER.log(Level.FINE, "Started with arguments: {0}", Arrays.toString(args));
try {
randomFailingAlgorithm();
}
catch (IllegalStateException e) {
LOGGER.log(Level.SEVERE, "Exception caught", e);
System.exit(2);
}
LOGGER.fine("Finished successfully");
}
private static void randomFailingAlgorithm() {
double randomNumber = Math.random();
LOGGER.log(Level.FINE, "Generated random number: {0}", randomNumber);
if (randomNumber < 0.5) {
throw new IllegalStateException("Invalid phase of the Moon");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment