Created
April 29, 2016 12:39
-
-
Save relistan/06726b9a4b5696c043ad1bd652992cce to your computer and use it in GitHub Desktop.
logback_test.java
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 hello; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class MyApp1 { | |
final static Logger logger = LoggerFactory.getLogger(MyApp1.class); | |
private static void setDefaultUncaughtExceptionHandler() { | |
try { | |
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { | |
@Override | |
public void uncaughtException(Thread t, Throwable e) { | |
logger.error("Something REALLY went wrong", e); | |
} | |
}); | |
} catch (SecurityException e) { | |
logger.error("Could not set the Default Uncaught Exception Handler", e); | |
} | |
} | |
public static void main(String[] args) throws Exception { | |
setDefaultUncaughtExceptionHandler(); | |
logger.info("Entering application."); | |
logger.info("About to throw from application."); | |
try { | |
throw new Exception("Oh no!"); | |
} catch(Exception e) { | |
logger.error("Something went wrong", e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment