Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
UncaughtExceptionLogger |
|
| 1.0;1 |
1 | /* | |
2 | * This file is part of AceLogger. | |
3 | * | |
4 | * AceLogger is free software: you can redistribute it and/or modify it under the terms of the GNU | |
5 | * Lesser General Public License as published by the Free Software Foundation, either version 3 of | |
6 | * the License, or (at your option) any later version. | |
7 | * | |
8 | * AceLogger is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | |
9 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
10 | * Lesser General Public License for more details. | |
11 | * | |
12 | * You should have received a copy of the GNU Lesser General Public License along with AceLogger. | |
13 | * If not, see <http://www.gnu.org/licenses/lgpl-3.0.html>. | |
14 | */ | |
15 | package net.sourceforge.acelogger.execution; | |
16 | ||
17 | import java.lang.Thread.UncaughtExceptionHandler; | |
18 | ||
19 | /** | |
20 | * An implementation of {@link UncaughtExceptionHandler} that logs the exception using the internal | |
21 | * logger. | |
22 | * | |
23 | * @author Zardi (https://sourceforge.net/users/daniel_zardi) | |
24 | * @version 1.0.0 | |
25 | * @since 1.0.0 | |
26 | */ | |
27 | public final class UncaughtExceptionLogger implements UncaughtExceptionHandler { | |
28 | ||
29 | /** | |
30 | * A instance of this class (the only one). | |
31 | */ | |
32 | 1 | private static final UncaughtExceptionLogger INSTANCE = new UncaughtExceptionLogger(); |
33 | ||
34 | /** | |
35 | * This constructor prevents the instantiation of this utility class. | |
36 | * | |
37 | * @since 1.0.0 | |
38 | */ | |
39 | 1 | private UncaughtExceptionLogger() { } |
40 | ||
41 | /** | |
42 | * Logs any uncaught exceptions using the internal logger. | |
43 | * | |
44 | * @param threadOfOrigin The thread where the uncaught exception was thrown. | |
45 | * @param uncaughtException The exception itself. | |
46 | * @since 1.0.0 | |
47 | */ | |
48 | public void uncaughtException(Thread threadOfOrigin, Throwable uncaughtException) { | |
49 | 0 | LogController.getInternalLogger().error( |
50 | "UncaughtExceptionLogger.message", uncaughtException, threadOfOrigin.getName() | |
51 | ); | |
52 | 0 | } |
53 | ||
54 | /** | |
55 | * Returns an instance of {@link UncaughtExceptionLogger}, which is a singleton. | |
56 | * | |
57 | * @return An instance of this class. | |
58 | * @since 1.0.0 | |
59 | */ | |
60 | public static UncaughtExceptionLogger getInstance() { | |
61 | 1 | return INSTANCE; |
62 | } | |
63 | } |