Created
September 28, 2016 18:21
-
-
Save anonymous/108bfaffc17ab1016369b1a2e46fa067 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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