--- java/org/apache/catalina/core/ContainerBase.java (revision 1761912) +++ java/org/apache/catalina/core/ContainerBase.java (working copy) @@ -357,7 +357,7 @@ if (logger != null) return (logger); - logger = LogFactory.getLog(logName()); + logger = LogFactory.getLog(getLogName()); return (logger); } @@ -364,6 +364,34 @@ /** + * @return the abbreviated name of this container for logging messages + */ + @Override + public String getLogName() { + + if (logName != null) { + return logName; + } + String loggerName = null; + Container current = this; + while (current != null) { + String name = current.getName(); + if ((name == null) || (name.equals(""))) { + name = "/"; + } else if (name.startsWith("##")) { + name = "/" + name; + } + loggerName = "[" + name + "]" + + ((loggerName != null) ? ("." + loggerName) : ""); + current = current.getParent(); + } + logName = ContainerBase.class.getName() + "." + loggerName; + return logName; + + } + + + /** * Return the Cluster with which this Container is associated. If there is * no associated Cluster, return the Cluster associated with our parent * Container (if any); otherwise return null. @@ -1183,33 +1211,6 @@ } - /** - * @return the abbreviated name of this container for logging messages - */ - protected String logName() { - - if (logName != null) { - return logName; - } - String loggerName = null; - Container current = this; - while (current != null) { - String name = current.getName(); - if ((name == null) || (name.equals(""))) { - name = "/"; - } else if (name.startsWith("##")) { - name = "/" + name; - } - loggerName = "[" + name + "]" - + ((loggerName != null) ? ("." + loggerName) : ""); - current = current.getParent(); - } - logName = ContainerBase.class.getName() + "." + loggerName; - return logName; - - } - - // -------------------- JMX and Registration -------------------- @Override --- java/org/apache/catalina/valves/rewrite/RewriteValve.java (revision 1761912) +++ java/org/apache/catalina/valves/rewrite/RewriteValve.java (working copy) @@ -47,6 +47,7 @@ import org.apache.catalina.connector.Response; import org.apache.catalina.util.URLEncoder; import org.apache.catalina.valves.ValveBase; +import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.buf.CharChunk; import org.apache.tomcat.util.buf.MessageBytes; import org.apache.tomcat.util.buf.UriUtil; @@ -143,7 +144,15 @@ this.enabled = enabled; } + @Override + protected void initInternal() throws LifecycleException { + super.initInternal(); + containerLog = LogFactory.getLog(getContainer().getLogName() + ".rewrite"); + } + + + @Override protected synchronized void startInternal() throws LifecycleException { super.startInternal(); @@ -155,11 +164,11 @@ context = true; is = ((Context) getContainer()).getServletContext() .getResourceAsStream("/WEB-INF/" + resourcePath); - if (container.getLogger().isDebugEnabled()) { + if (containerLog.isDebugEnabled()) { if (is == null) { - container.getLogger().debug("No configuration resource found: /WEB-INF/" + resourcePath); + containerLog.debug("No configuration resource found: /WEB-INF/" + resourcePath); } else { - container.getLogger().debug("Read configuration from: /WEB-INF/" + resourcePath); + containerLog.debug("Read configuration from: /WEB-INF/" + resourcePath); } } } else if (getContainer() instanceof Host) { @@ -170,21 +179,21 @@ // Use getResource and getResourceAsStream is = getClass().getClassLoader() .getResourceAsStream(resourceName); - if (is != null && container.getLogger().isDebugEnabled()) { - container.getLogger().debug("Read configuration from CL at " + resourceName); + if (is != null && containerLog.isDebugEnabled()) { + containerLog.debug("Read configuration from CL at " + resourceName); } } else { - if (container.getLogger().isDebugEnabled()) { - container.getLogger().debug("Read configuration from " + file.getAbsolutePath()); + if (containerLog.isDebugEnabled()) { + containerLog.debug("Read configuration from " + file.getAbsolutePath()); } is = new FileInputStream(file); } - if ((is == null) && (container.getLogger().isDebugEnabled())) { - container.getLogger().debug("No configuration resource found: " + resourceName + + if ((is == null) && (containerLog.isDebugEnabled())) { + containerLog.debug("No configuration resource found: " + resourceName + " in " + getConfigBase() + " or in the classloader"); } } catch (Exception e) { - container.getLogger().error("Error opening configuration", e); + containerLog.error("Error opening configuration", e); } } @@ -197,12 +206,12 @@ BufferedReader reader = new BufferedReader(isr)) { parse(reader); } catch (IOException ioe) { - container.getLogger().error("Error closing configuration", ioe); + containerLog.error("Error closing configuration", ioe); } finally { try { is.close(); } catch (IOException e) { - container.getLogger().error("Error closing configuration", e); + containerLog.error("Error closing configuration", e); } } @@ -238,8 +247,8 @@ Object result = parse(line); if (result instanceof RewriteRule) { RewriteRule rule = (RewriteRule) result; - if (container.getLogger().isDebugEnabled()) { - container.getLogger().debug("Add rule with pattern " + rule.getPatternString() + if (containerLog.isDebugEnabled()) { + containerLog.debug("Add rule with pattern " + rule.getPatternString() + " and substitution " + rule.getSubstitutionString()); } for (int i = (conditions.size() - 1); i > 0; i--) { @@ -248,9 +257,9 @@ } } for (int i = 0; i < conditions.size(); i++) { - if (container.getLogger().isDebugEnabled()) { + if (containerLog.isDebugEnabled()) { RewriteCond cond = conditions.get(i); - container.getLogger().debug("Add condition " + cond.getCondPattern() + containerLog.debug("Add condition " + cond.getCondPattern() + " test " + cond.getTestString() + " to rule with pattern " + rule.getPatternString() + " and substitution " + rule.getSubstitutionString() + (cond.isOrnext() ? " [OR]" : "") @@ -271,7 +280,7 @@ } } } catch (IOException e) { - container.getLogger().error("Error reading configuration", e); + containerLog.error("Error reading configuration", e); } } this.rules = rules.toArray(new RewriteRule[0]); @@ -338,8 +347,8 @@ CharSequence test = (rule.isHost()) ? host : urlDecoded; CharSequence newtest = rule.evaluate(test, resolver); if (newtest != null && !test.equals(newtest.toString())) { - if (container.getLogger().isDebugEnabled()) { - container.getLogger().debug("Rewrote " + test + " as " + newtest + if (containerLog.isDebugEnabled()) { + containerLog.debug("Rewrote " + test + " as " + newtest + " with rule pattern " + rule.getPatternString()); } if (rule.isHost()) { --- java/org/apache/catalina/Container.java (revision 1761912) +++ java/org/apache/catalina/Container.java (working copy) @@ -123,6 +123,13 @@ /** + * Return the logger name that the container will use. + * @return the abbreviated name of this container for logging messages + */ + public String getLogName(); + + + /** * Obtain the JMX name for this container. * * @return the JMX name associated with this container.