mirror of
https://github.com/corda/corda.git
synced 2025-01-04 04:04:27 +00:00
fix log level inheritance
A Logger which has not had a level set explicitly should inherit its effective level from its parent, not just default to INFO.
This commit is contained in:
parent
b28142a837
commit
7a768f2c69
@ -32,7 +32,6 @@ public class Logger {
|
||||
if (name.equals("")) return rootLogger;
|
||||
Logger logger = new Logger(name);
|
||||
logger.parent = rootLogger;
|
||||
logger.setLevel(Level.INFO);
|
||||
return logger;
|
||||
}
|
||||
|
||||
@ -60,6 +59,14 @@ public class Logger {
|
||||
log(Level.FINE, Method.getCaller(), message, null);
|
||||
}
|
||||
|
||||
public void finer(String message) {
|
||||
log(Level.FINER, Method.getCaller(), message, null);
|
||||
}
|
||||
|
||||
public void finest(String message) {
|
||||
log(Level.FINEST, Method.getCaller(), message, null);
|
||||
}
|
||||
|
||||
public void info(String message) {
|
||||
log(Level.INFO, Method.getCaller(), message, null);
|
||||
}
|
||||
@ -155,7 +162,7 @@ public class Logger {
|
||||
}
|
||||
|
||||
public boolean isLoggable(Level level) {
|
||||
return level.intValue() >= levelValue.intValue();
|
||||
return level.intValue() >= getEffectiveLevel().intValue();
|
||||
}
|
||||
|
||||
private static class DefaultHandler extends Handler {
|
||||
|
@ -95,6 +95,10 @@ public class Logging {
|
||||
private void e() throws Exception {
|
||||
throw new Exception("Started here");
|
||||
}
|
||||
|
||||
private static void expect(boolean v) {
|
||||
if (! v) throw new RuntimeException();
|
||||
}
|
||||
|
||||
private static final boolean useCustomHandler = true;
|
||||
public static void main(String args[]) {
|
||||
@ -107,5 +111,37 @@ public class Logging {
|
||||
|
||||
Logging me = new Logging();
|
||||
me.run();
|
||||
|
||||
{ final boolean[] logged = new boolean[1];
|
||||
Logger root = Logger.getLogger("");
|
||||
for (Handler h : root.getHandlers()) root.removeHandler(h);
|
||||
root.setLevel(Level.FINER);
|
||||
root.addHandler(new Handler() {
|
||||
public void publish(LogRecord r) {
|
||||
logged[0] = true;
|
||||
}
|
||||
});
|
||||
|
||||
Logger foo = Logger.getLogger("foo");
|
||||
expect(foo.getLevel() == null);
|
||||
expect(foo.getParent() == root);
|
||||
|
||||
foo.info("hi");
|
||||
expect(logged[0]);
|
||||
|
||||
logged[0] = false;
|
||||
foo.fine("hi");
|
||||
expect(logged[0]);
|
||||
|
||||
logged[0] = false;
|
||||
foo.finest("hi");
|
||||
expect(! logged[0]);
|
||||
|
||||
root.setLevel(Level.FINEST);
|
||||
|
||||
logged[0] = false;
|
||||
foo.finest("hi");
|
||||
expect(logged[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user