diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java index 18438aad1bf..b6100b566ee 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java @@ -816,10 +816,10 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu } } - if (StringUtil.isNotBlank(log_name)) + if (StringUtil.isBlank(log_name)) { - // try hex of hashcode - log_name = Integer.toHexString(hashCode()); + // an empty context path is the ROOT context + log_name = "ROOT"; } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerTest.java index 430a4261b0b..626adec2e5e 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerTest.java @@ -458,15 +458,82 @@ public class ContextHandlerTest } @Test - public void testLogName() throws Exception + public void testLogNameFromDisplayName() throws Exception { ContextHandler handler = new ContextHandler(); handler.setServer(new Server()); - handler.setDisplayName("."); + handler.setDisplayName("An Interesting Project: app.tast.ic"); try { handler.start(); - assertThat("handler.get", handler.getLogger().getName(), is(ContextHandler.class.getName())); + assertThat("handler.get", handler.getLogger().getName(), is(ContextHandler.class.getName() + ".An_Interesting_Project__app_tast_ic")); + } + finally + { + handler.stop(); + } + } + + @Test + public void testLogNameFromContextPath_Deep() throws Exception + { + ContextHandler handler = new ContextHandler(); + handler.setServer(new Server()); + handler.setContextPath("/app/tast/ic"); + try + { + handler.start(); + assertThat("handler.get", handler.getLogger().getName(), is(ContextHandler.class.getName() + ".app_tast_ic")); + } + finally + { + handler.stop(); + } + } + + @Test + public void testLogNameFromContextPath_Root() throws Exception + { + ContextHandler handler = new ContextHandler(); + handler.setServer(new Server()); + handler.setContextPath(""); + try + { + handler.start(); + assertThat("handler.get", handler.getLogger().getName(), is(ContextHandler.class.getName() + ".ROOT")); + } + finally + { + handler.stop(); + } + } + + @Test + public void testLogNameFromContextPath_Undefined() throws Exception + { + ContextHandler handler = new ContextHandler(); + handler.setServer(new Server()); + try + { + handler.start(); + assertThat("handler.get", handler.getLogger().getName(), is(ContextHandler.class.getName() + ".ROOT")); + } + finally + { + handler.stop(); + } + } + + @Test + public void testLogNameFromContextPath_Empty() throws Exception + { + ContextHandler handler = new ContextHandler(); + handler.setServer(new Server()); + handler.setContextPath(""); + try + { + handler.start(); + assertThat("handler.get", handler.getLogger().getName(), is(ContextHandler.class.getName() + ".ROOT")); } finally {