From 012797a82c7ee448c12ae45b63e349b610494d6d Mon Sep 17 00:00:00 2001 From: Luca Cavanna Date: Wed, 11 Sep 2013 16:04:08 +0200 Subject: [PATCH] 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 --- src/main/java/org/elasticsearch/common/logging/Loggers.java | 2 +- .../org/elasticsearch/junit/listeners/LoggingListener.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/elasticsearch/common/logging/Loggers.java b/src/main/java/org/elasticsearch/common/logging/Loggers.java index 7d1899031d9..665f68803f7 100644 --- a/src/main/java/org/elasticsearch/common/logging/Loggers.java +++ b/src/main/java/org/elasticsearch/common/logging/Loggers.java @@ -110,7 +110,7 @@ public class Loggers { } public static ESLogger getLogger(String s) { - return ESLoggerFactory.getLogger(s); + return ESLoggerFactory.getLogger(getLoggerName(s)); } public static ESLogger getLogger(Class clazz) { diff --git a/src/test/java/org/elasticsearch/junit/listeners/LoggingListener.java b/src/test/java/org/elasticsearch/junit/listeners/LoggingListener.java index 5a9faf4bec5..af9bfcca91e 100644 --- a/src/test/java/org/elasticsearch/junit/listeners/LoggingListener.java +++ b/src/test/java/org/elasticsearch/junit/listeners/LoggingListener.java @@ -20,6 +20,7 @@ package org.elasticsearch.junit.listeners; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLoggerFactory; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.junit.annotations.TestLogging; import org.junit.runner.Description; import org.junit.runner.notification.RunListener; @@ -75,6 +76,6 @@ public class LoggingListener extends RunListener { if (loggerName.equalsIgnoreCase("_root")) { return ESLoggerFactory.getRootLogger(); } - return ESLoggerFactory.getLogger(loggerName); + return Loggers.getLogger(loggerName); } }