提交 0b829c47 编写于 作者: D dfuchs

8024525: Make Logger log methods call isLoggable()

Summary: This changeset makes the various Logger logging method call isLoggable() instead of inlining the level checks.
Reviewed-by: mchung, alanb
上级 e52f10cb
...@@ -635,7 +635,7 @@ public class Logger { ...@@ -635,7 +635,7 @@ public class Logger {
* @param record the LogRecord to be published * @param record the LogRecord to be published
*/ */
public void log(LogRecord record) { public void log(LogRecord record) {
if (record.getLevel().intValue() < levelValue || levelValue == offValue) { if (!isLoggable(record.getLevel())) {
return; return;
} }
Filter theFilter = filter; Filter theFilter = filter;
...@@ -689,7 +689,7 @@ public class Logger { ...@@ -689,7 +689,7 @@ public class Logger {
* @param msg The string message (or a key in the message catalog) * @param msg The string message (or a key in the message catalog)
*/ */
public void log(Level level, String msg) { public void log(Level level, String msg) {
if (level.intValue() < levelValue || levelValue == offValue) { if (!isLoggable(level)) {
return; return;
} }
LogRecord lr = new LogRecord(level, msg); LogRecord lr = new LogRecord(level, msg);
...@@ -710,7 +710,7 @@ public class Logger { ...@@ -710,7 +710,7 @@ public class Logger {
* desired log message * desired log message
*/ */
public void log(Level level, Supplier<String> msgSupplier) { public void log(Level level, Supplier<String> msgSupplier) {
if (level.intValue() < levelValue || levelValue == offValue) { if (!isLoggable(level)) {
return; return;
} }
LogRecord lr = new LogRecord(level, msgSupplier.get()); LogRecord lr = new LogRecord(level, msgSupplier.get());
...@@ -729,7 +729,7 @@ public class Logger { ...@@ -729,7 +729,7 @@ public class Logger {
* @param param1 parameter to the message * @param param1 parameter to the message
*/ */
public void log(Level level, String msg, Object param1) { public void log(Level level, String msg, Object param1) {
if (level.intValue() < levelValue || levelValue == offValue) { if (!isLoggable(level)) {
return; return;
} }
LogRecord lr = new LogRecord(level, msg); LogRecord lr = new LogRecord(level, msg);
...@@ -750,7 +750,7 @@ public class Logger { ...@@ -750,7 +750,7 @@ public class Logger {
* @param params array of parameters to the message * @param params array of parameters to the message
*/ */
public void log(Level level, String msg, Object params[]) { public void log(Level level, String msg, Object params[]) {
if (level.intValue() < levelValue || levelValue == offValue) { if (!isLoggable(level)) {
return; return;
} }
LogRecord lr = new LogRecord(level, msg); LogRecord lr = new LogRecord(level, msg);
...@@ -775,7 +775,7 @@ public class Logger { ...@@ -775,7 +775,7 @@ public class Logger {
* @param thrown Throwable associated with log message. * @param thrown Throwable associated with log message.
*/ */
public void log(Level level, String msg, Throwable thrown) { public void log(Level level, String msg, Throwable thrown) {
if (level.intValue() < levelValue || levelValue == offValue) { if (!isLoggable(level)) {
return; return;
} }
LogRecord lr = new LogRecord(level, msg); LogRecord lr = new LogRecord(level, msg);
...@@ -803,7 +803,7 @@ public class Logger { ...@@ -803,7 +803,7 @@ public class Logger {
* @since 1.8 * @since 1.8
*/ */
public void log(Level level, Throwable thrown, Supplier<String> msgSupplier) { public void log(Level level, Throwable thrown, Supplier<String> msgSupplier) {
if (level.intValue() < levelValue || levelValue == offValue) { if (!isLoggable(level)) {
return; return;
} }
LogRecord lr = new LogRecord(level, msgSupplier.get()); LogRecord lr = new LogRecord(level, msgSupplier.get());
...@@ -829,7 +829,7 @@ public class Logger { ...@@ -829,7 +829,7 @@ public class Logger {
* @param msg The string message (or a key in the message catalog) * @param msg The string message (or a key in the message catalog)
*/ */
public void logp(Level level, String sourceClass, String sourceMethod, String msg) { public void logp(Level level, String sourceClass, String sourceMethod, String msg) {
if (level.intValue() < levelValue || levelValue == offValue) { if (!isLoggable(level)) {
return; return;
} }
LogRecord lr = new LogRecord(level, msg); LogRecord lr = new LogRecord(level, msg);
...@@ -856,7 +856,7 @@ public class Logger { ...@@ -856,7 +856,7 @@ public class Logger {
*/ */
public void logp(Level level, String sourceClass, String sourceMethod, public void logp(Level level, String sourceClass, String sourceMethod,
Supplier<String> msgSupplier) { Supplier<String> msgSupplier) {
if (level.intValue() < levelValue || levelValue == offValue) { if (!isLoggable(level)) {
return; return;
} }
LogRecord lr = new LogRecord(level, msgSupplier.get()); LogRecord lr = new LogRecord(level, msgSupplier.get());
...@@ -881,7 +881,7 @@ public class Logger { ...@@ -881,7 +881,7 @@ public class Logger {
*/ */
public void logp(Level level, String sourceClass, String sourceMethod, public void logp(Level level, String sourceClass, String sourceMethod,
String msg, Object param1) { String msg, Object param1) {
if (level.intValue() < levelValue || levelValue == offValue) { if (!isLoggable(level)) {
return; return;
} }
LogRecord lr = new LogRecord(level, msg); LogRecord lr = new LogRecord(level, msg);
...@@ -908,7 +908,7 @@ public class Logger { ...@@ -908,7 +908,7 @@ public class Logger {
*/ */
public void logp(Level level, String sourceClass, String sourceMethod, public void logp(Level level, String sourceClass, String sourceMethod,
String msg, Object params[]) { String msg, Object params[]) {
if (level.intValue() < levelValue || levelValue == offValue) { if (!isLoggable(level)) {
return; return;
} }
LogRecord lr = new LogRecord(level, msg); LogRecord lr = new LogRecord(level, msg);
...@@ -939,7 +939,7 @@ public class Logger { ...@@ -939,7 +939,7 @@ public class Logger {
*/ */
public void logp(Level level, String sourceClass, String sourceMethod, public void logp(Level level, String sourceClass, String sourceMethod,
String msg, Throwable thrown) { String msg, Throwable thrown) {
if (level.intValue() < levelValue || levelValue == offValue) { if (!isLoggable(level)) {
return; return;
} }
LogRecord lr = new LogRecord(level, msg); LogRecord lr = new LogRecord(level, msg);
...@@ -973,7 +973,7 @@ public class Logger { ...@@ -973,7 +973,7 @@ public class Logger {
*/ */
public void logp(Level level, String sourceClass, String sourceMethod, public void logp(Level level, String sourceClass, String sourceMethod,
Throwable thrown, Supplier<String> msgSupplier) { Throwable thrown, Supplier<String> msgSupplier) {
if (level.intValue() < levelValue || levelValue == offValue) { if (!isLoggable(level)) {
return; return;
} }
LogRecord lr = new LogRecord(level, msgSupplier.get()); LogRecord lr = new LogRecord(level, msgSupplier.get());
...@@ -1021,7 +1021,7 @@ public class Logger { ...@@ -1021,7 +1021,7 @@ public class Logger {
*/ */
public void logrb(Level level, String sourceClass, String sourceMethod, public void logrb(Level level, String sourceClass, String sourceMethod,
String bundleName, String msg) { String bundleName, String msg) {
if (level.intValue() < levelValue || levelValue == offValue) { if (!isLoggable(level)) {
return; return;
} }
LogRecord lr = new LogRecord(level, msg); LogRecord lr = new LogRecord(level, msg);
...@@ -1052,7 +1052,7 @@ public class Logger { ...@@ -1052,7 +1052,7 @@ public class Logger {
*/ */
public void logrb(Level level, String sourceClass, String sourceMethod, public void logrb(Level level, String sourceClass, String sourceMethod,
String bundleName, String msg, Object param1) { String bundleName, String msg, Object param1) {
if (level.intValue() < levelValue || levelValue == offValue) { if (!isLoggable(level)) {
return; return;
} }
LogRecord lr = new LogRecord(level, msg); LogRecord lr = new LogRecord(level, msg);
...@@ -1085,7 +1085,7 @@ public class Logger { ...@@ -1085,7 +1085,7 @@ public class Logger {
*/ */
public void logrb(Level level, String sourceClass, String sourceMethod, public void logrb(Level level, String sourceClass, String sourceMethod,
String bundleName, String msg, Object params[]) { String bundleName, String msg, Object params[]) {
if (level.intValue() < levelValue || levelValue == offValue) { if (!isLoggable(level)) {
return; return;
} }
LogRecord lr = new LogRecord(level, msg); LogRecord lr = new LogRecord(level, msg);
...@@ -1122,7 +1122,7 @@ public class Logger { ...@@ -1122,7 +1122,7 @@ public class Logger {
*/ */
public void logrb(Level level, String sourceClass, String sourceMethod, public void logrb(Level level, String sourceClass, String sourceMethod,
String bundleName, String msg, Throwable thrown) { String bundleName, String msg, Throwable thrown) {
if (level.intValue() < levelValue || levelValue == offValue) { if (!isLoggable(level)) {
return; return;
} }
LogRecord lr = new LogRecord(level, msg); LogRecord lr = new LogRecord(level, msg);
...@@ -1148,9 +1148,6 @@ public class Logger { ...@@ -1148,9 +1148,6 @@ public class Logger {
* @param sourceMethod name of method that is being entered * @param sourceMethod name of method that is being entered
*/ */
public void entering(String sourceClass, String sourceMethod) { public void entering(String sourceClass, String sourceMethod) {
if (Level.FINER.intValue() < levelValue) {
return;
}
logp(Level.FINER, sourceClass, sourceMethod, "ENTRY"); logp(Level.FINER, sourceClass, sourceMethod, "ENTRY");
} }
...@@ -1167,11 +1164,7 @@ public class Logger { ...@@ -1167,11 +1164,7 @@ public class Logger {
* @param param1 parameter to the method being entered * @param param1 parameter to the method being entered
*/ */
public void entering(String sourceClass, String sourceMethod, Object param1) { public void entering(String sourceClass, String sourceMethod, Object param1) {
if (Level.FINER.intValue() < levelValue) { logp(Level.FINER, sourceClass, sourceMethod, "ENTRY {0}", param1);
return;
}
Object params[] = { param1 };
logp(Level.FINER, sourceClass, sourceMethod, "ENTRY {0}", params);
} }
/** /**
...@@ -1188,14 +1181,12 @@ public class Logger { ...@@ -1188,14 +1181,12 @@ public class Logger {
* @param params array of parameters to the method being entered * @param params array of parameters to the method being entered
*/ */
public void entering(String sourceClass, String sourceMethod, Object params[]) { public void entering(String sourceClass, String sourceMethod, Object params[]) {
if (Level.FINER.intValue() < levelValue) {
return;
}
String msg = "ENTRY"; String msg = "ENTRY";
if (params == null ) { if (params == null ) {
logp(Level.FINER, sourceClass, sourceMethod, msg); logp(Level.FINER, sourceClass, sourceMethod, msg);
return; return;
} }
if (!isLoggable(Level.FINER)) return;
for (int i = 0; i < params.length; i++) { for (int i = 0; i < params.length; i++) {
msg = msg + " {" + i + "}"; msg = msg + " {" + i + "}";
} }
...@@ -1213,9 +1204,6 @@ public class Logger { ...@@ -1213,9 +1204,6 @@ public class Logger {
* @param sourceMethod name of the method * @param sourceMethod name of the method
*/ */
public void exiting(String sourceClass, String sourceMethod) { public void exiting(String sourceClass, String sourceMethod) {
if (Level.FINER.intValue() < levelValue) {
return;
}
logp(Level.FINER, sourceClass, sourceMethod, "RETURN"); logp(Level.FINER, sourceClass, sourceMethod, "RETURN");
} }
...@@ -1233,10 +1221,6 @@ public class Logger { ...@@ -1233,10 +1221,6 @@ public class Logger {
* @param result Object that is being returned * @param result Object that is being returned
*/ */
public void exiting(String sourceClass, String sourceMethod, Object result) { public void exiting(String sourceClass, String sourceMethod, Object result) {
if (Level.FINER.intValue() < levelValue) {
return;
}
Object params[] = { result };
logp(Level.FINER, sourceClass, sourceMethod, "RETURN {0}", result); logp(Level.FINER, sourceClass, sourceMethod, "RETURN {0}", result);
} }
...@@ -1262,7 +1246,7 @@ public class Logger { ...@@ -1262,7 +1246,7 @@ public class Logger {
* @param thrown The Throwable that is being thrown. * @param thrown The Throwable that is being thrown.
*/ */
public void throwing(String sourceClass, String sourceMethod, Throwable thrown) { public void throwing(String sourceClass, String sourceMethod, Throwable thrown) {
if (Level.FINER.intValue() < levelValue || levelValue == offValue ) { if (!isLoggable(Level.FINER)) {
return; return;
} }
LogRecord lr = new LogRecord(Level.FINER, "THROW"); LogRecord lr = new LogRecord(Level.FINER, "THROW");
...@@ -1286,9 +1270,6 @@ public class Logger { ...@@ -1286,9 +1270,6 @@ public class Logger {
* @param msg The string message (or a key in the message catalog) * @param msg The string message (or a key in the message catalog)
*/ */
public void severe(String msg) { public void severe(String msg) {
if (Level.SEVERE.intValue() < levelValue) {
return;
}
log(Level.SEVERE, msg); log(Level.SEVERE, msg);
} }
...@@ -1302,9 +1283,6 @@ public class Logger { ...@@ -1302,9 +1283,6 @@ public class Logger {
* @param msg The string message (or a key in the message catalog) * @param msg The string message (or a key in the message catalog)
*/ */
public void warning(String msg) { public void warning(String msg) {
if (Level.WARNING.intValue() < levelValue) {
return;
}
log(Level.WARNING, msg); log(Level.WARNING, msg);
} }
...@@ -1318,9 +1296,6 @@ public class Logger { ...@@ -1318,9 +1296,6 @@ public class Logger {
* @param msg The string message (or a key in the message catalog) * @param msg The string message (or a key in the message catalog)
*/ */
public void info(String msg) { public void info(String msg) {
if (Level.INFO.intValue() < levelValue) {
return;
}
log(Level.INFO, msg); log(Level.INFO, msg);
} }
...@@ -1334,9 +1309,6 @@ public class Logger { ...@@ -1334,9 +1309,6 @@ public class Logger {
* @param msg The string message (or a key in the message catalog) * @param msg The string message (or a key in the message catalog)
*/ */
public void config(String msg) { public void config(String msg) {
if (Level.CONFIG.intValue() < levelValue) {
return;
}
log(Level.CONFIG, msg); log(Level.CONFIG, msg);
} }
...@@ -1350,9 +1322,6 @@ public class Logger { ...@@ -1350,9 +1322,6 @@ public class Logger {
* @param msg The string message (or a key in the message catalog) * @param msg The string message (or a key in the message catalog)
*/ */
public void fine(String msg) { public void fine(String msg) {
if (Level.FINE.intValue() < levelValue) {
return;
}
log(Level.FINE, msg); log(Level.FINE, msg);
} }
...@@ -1366,9 +1335,6 @@ public class Logger { ...@@ -1366,9 +1335,6 @@ public class Logger {
* @param msg The string message (or a key in the message catalog) * @param msg The string message (or a key in the message catalog)
*/ */
public void finer(String msg) { public void finer(String msg) {
if (Level.FINER.intValue() < levelValue) {
return;
}
log(Level.FINER, msg); log(Level.FINER, msg);
} }
...@@ -1382,9 +1348,6 @@ public class Logger { ...@@ -1382,9 +1348,6 @@ public class Logger {
* @param msg The string message (or a key in the message catalog) * @param msg The string message (or a key in the message catalog)
*/ */
public void finest(String msg) { public void finest(String msg) {
if (Level.FINEST.intValue() < levelValue) {
return;
}
log(Level.FINEST, msg); log(Level.FINEST, msg);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册