Cleanup : outdated code removed and unnecessary static section and variables

Motivation:

Old code doesn't needed anymore due to logger factory initialization.

Modifications :

Removed static section and useless static variables;
Logging concatenations replaced with placeholders.

Result:

Cleaner, simpler code doing the same
This commit is contained in:
Dmitriy Dumanskiy 2016-08-02 00:30:49 +03:00 committed by Norman Maurer
parent 82b22d6f11
commit b427a8c8bd

View File

@ -20,8 +20,6 @@ import io.netty.util.internal.logging.InternalLoggerFactory;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
/**
@ -29,15 +27,7 @@ import java.util.regex.Pattern;
*/
public final class SystemPropertyUtil {
private static boolean initializedLogger;
private static final InternalLogger logger;
private static boolean loggedException;
static {
initializedLogger = false;
logger = InternalLoggerFactory.getInstance(SystemPropertyUtil.class);
initializedLogger = true;
}
private static final InternalLogger logger = InternalLoggerFactory.getInstance(SystemPropertyUtil.class);
/**
* Returns {@code true} if and only if the system property with the specified {@code key}
@ -87,10 +77,7 @@ public final class SystemPropertyUtil {
});
}
} catch (Exception e) {
if (!loggedException) {
log("Unable to retrieve a system property '" + key + "'; default values will be used.", e);
loggedException = true;
}
logger.warn("Unable to retrieve a system property '{}'; default values will be used.", key, e);
}
if (value == null) {
@ -128,9 +115,10 @@ public final class SystemPropertyUtil {
return false;
}
log(
"Unable to parse the boolean system property '" + key + "':" + value + " - " +
"using the default value: " + def);
logger.warn(
"Unable to parse the boolean system property '{}':{} - using the default value: {}",
key, value, def
);
return def;
}
@ -161,9 +149,10 @@ public final class SystemPropertyUtil {
}
}
log(
"Unable to parse the integer system property '" + key + "':" + value + " - " +
"using the default value: " + def);
logger.warn(
"Unable to parse the integer system property '{}':{} - using the default value: {}",
key, value, def
);
return def;
}
@ -192,31 +181,14 @@ public final class SystemPropertyUtil {
}
}
log(
"Unable to parse the long integer system property '" + key + "':" + value + " - " +
"using the default value: " + def);
logger.warn(
"Unable to parse the long integer system property '{}':{} - using the default value: {}",
key, value, def
);
return def;
}
private static void log(String msg) {
if (initializedLogger) {
logger.warn(msg);
} else {
// Use JDK logging if logger was not initialized yet.
Logger.getLogger(SystemPropertyUtil.class.getName()).log(Level.WARNING, msg);
}
}
private static void log(String msg, Exception e) {
if (initializedLogger) {
logger.warn(msg, e);
} else {
// Use JDK logging if logger was not initialized yet.
Logger.getLogger(SystemPropertyUtil.class.getName()).log(Level.WARNING, msg, e);
}
}
private SystemPropertyUtil() {
// Unused
}