1
0

Use try-with-resources

This commit is contained in:
Gary Gregory
2023-11-26 10:22:37 -05:00
parent a1c174c086
commit 8ed85820ce

View File

@@ -133,19 +133,12 @@ public class SimpleLog implements Log, Serializable {
// Override with system properties. // Override with system properties.
static { static {
// Add props from the resource simplelog.properties // Add props from the resource simplelog.properties
final InputStream in = getResourceAsStream("simplelog.properties"); try (InputStream in = getResourceAsStream("simplelog.properties")) {
if (null != in) { if (null != in) {
try {
simpleLogProps.load(in); simpleLogProps.load(in);
} catch (final IOException ignore) {
// ignored
} finally {
try {
in.close();
} catch (final IOException ignore) {
// ignored
}
} }
} catch (IOException ignore) {
// Ignore
} }
showLogName = getBooleanProperty(systemPrefix + "showlogname", showLogName); showLogName = getBooleanProperty(systemPrefix + "showlogname", showLogName);
@@ -153,8 +146,7 @@ public class SimpleLog implements Log, Serializable {
showDateTime = getBooleanProperty(systemPrefix + "showdatetime", showDateTime); showDateTime = getBooleanProperty(systemPrefix + "showdatetime", showDateTime);
if (showDateTime) { if (showDateTime) {
dateTimeFormat = getStringProperty(systemPrefix + "dateTimeFormat", dateTimeFormat = getStringProperty(systemPrefix + "dateTimeFormat", dateTimeFormat);
dateTimeFormat);
try { try {
dateFormatter = new SimpleDateFormat(dateTimeFormat); dateFormatter = new SimpleDateFormat(dateTimeFormat);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
@@ -536,12 +528,24 @@ public class SimpleLog implements Log, Serializable {
// Append a readable representation of the log level // Append a readable representation of the log level
switch (type) { switch (type) {
case SimpleLog.LOG_LEVEL_TRACE: buf.append("[TRACE] "); break; case SimpleLog.LOG_LEVEL_TRACE:
case SimpleLog.LOG_LEVEL_DEBUG: buf.append("[DEBUG] "); break; buf.append("[TRACE] ");
case SimpleLog.LOG_LEVEL_INFO: buf.append("[INFO] "); break; break;
case SimpleLog.LOG_LEVEL_WARN: buf.append("[WARN] "); break; case SimpleLog.LOG_LEVEL_DEBUG:
case SimpleLog.LOG_LEVEL_ERROR: buf.append("[ERROR] "); break; buf.append("[DEBUG] ");
case SimpleLog.LOG_LEVEL_FATAL: buf.append("[FATAL] "); break; break;
case SimpleLog.LOG_LEVEL_INFO:
buf.append("[INFO] ");
break;
case SimpleLog.LOG_LEVEL_WARN:
buf.append("[WARN] ");
break;
case SimpleLog.LOG_LEVEL_ERROR:
buf.append("[ERROR] ");
break;
case SimpleLog.LOG_LEVEL_FATAL:
buf.append("[FATAL] ");
break;
} }
// Append the name of the log instance if so configured // Append the name of the log instance if so configured