Loggers#getLogger static method to take into account the logger prefix

Improved LoggingListener (which reads and applies @TestLogging annotation) to take into account the logger prefix. We can now use the @TestLogging annotation and specify either the whole package name (e.g. o.e.action.metadata) or only the package name without the logger prefix (action.metadata), the custom log level will be properly applied in both cases
This commit is contained in:
Luca Cavanna 2013-09-11 16:04:08 +02:00
parent daedf853a0
commit 012797a82c
2 changed files with 3 additions and 2 deletions

View File

@ -110,7 +110,7 @@ public class Loggers {
} }
public static ESLogger getLogger(String s) { public static ESLogger getLogger(String s) {
return ESLoggerFactory.getLogger(s); return ESLoggerFactory.getLogger(getLoggerName(s));
} }
public static ESLogger getLogger(Class clazz) { public static ESLogger getLogger(Class clazz) {

View File

@ -20,6 +20,7 @@ package org.elasticsearch.junit.listeners;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.junit.annotations.TestLogging; import org.elasticsearch.junit.annotations.TestLogging;
import org.junit.runner.Description; import org.junit.runner.Description;
import org.junit.runner.notification.RunListener; import org.junit.runner.notification.RunListener;
@ -75,6 +76,6 @@ public class LoggingListener extends RunListener {
if (loggerName.equalsIgnoreCase("_root")) { if (loggerName.equalsIgnoreCase("_root")) {
return ESLoggerFactory.getRootLogger(); return ESLoggerFactory.getRootLogger();
} }
return ESLoggerFactory.getLogger(loggerName); return Loggers.getLogger(loggerName);
} }
} }