public final class UncaughtExceptionHandlers extends Object
Thread.UncaughtExceptionHandler which logs the last uncaught exception with a SLF4J Logger on ERROR level.| Modifier and Type | Class and Description |
|---|---|
static class |
UncaughtExceptionHandlers.LoggingSystemExitBuilder |
| Modifier and Type | Method and Description |
|---|---|
static UncaughtExceptionHandlers.LoggingSystemExitBuilder |
loggingSystemExitBuilder(String facility,
String host)
Returns a builder for an exception handler that bootstraps a GELF log appender, logs the uncaught exception
and then exits the system.
|
static Thread.UncaughtExceptionHandler |
systemExit()
Returns an exception handler that logs the uncaught exception to
System.err and then exits the system. |
public static UncaughtExceptionHandlers.LoggingSystemExitBuilder loggingSystemExitBuilder(String facility, String host)
public static void main(String[] args) {
Thread.currentThread().setUncaughtExceptionHandler(
UncaughtExceptionHandlers.loggingSystemExitBuilder("some-service", "log.example.com").build());
...
facility - The facility to use in the GELF messageshost - The host of the Graylog serverpublic static Thread.UncaughtExceptionHandler systemExit()
System.err and then exits the system.
This is particularly useful for the main thread, which may start up other, non-daemon threads, but fail to fully
initialize the application successfully. public static void main(String[] args) {
Thread.currentThread().setUncaughtExceptionHandler(
UncaughtExceptionHandlers.systemExit());
...
Copyright © 2016. All rights reserved.