ASF Bugzilla – Attachment 34287 Details for
Bug 60161
RewriteValve: Add more logging support similar to mod-rewrite
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Patch for providing detailed logging in RewriteValve
file_60161.txt (text/plain), 8.69 KB, created by
Santhana Preethi
on 2016-09-21 13:04:51 UTC
(
hide
)
Description:
Patch for providing detailed logging in RewriteValve
Filename:
MIME Type:
Creator:
Santhana Preethi
Created:
2016-09-21 13:04:51 UTC
Size:
8.69 KB
patch
obsolete
>Index: tomcat_19sep/java/org/apache/catalina/valves/rewrite/RewriteValve.java >=================================================================== >--- tomcat_19sep/java/org/apache/catalina/valves/rewrite/RewriteValve.java (revision 1761671) >+++ tomcat_19sep/java/org/apache/catalina/valves/rewrite/RewriteValve.java (working copy) >@@ -47,14 +47,24 @@ > import org.apache.catalina.connector.Response; > import org.apache.catalina.util.URLEncoder; > import org.apache.catalina.valves.ValveBase; >+import org.apache.juli.logging.Log; >+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; > import org.apache.tomcat.util.http.RequestUtil; > > public class RewriteValve extends ValveBase { >+ /* >+ * httpd supports configurable logging from level 1-10 for debugging >+ * Added similar logging support for the RewriteValve to replicate httpd behaviour >+ * Detailed logging when the logger level is set to DEBUG >+ */ > > static URLEncoder ENCODER = new URLEncoder(); >+ >+ private static final Log log = LogFactory.getLog(RewriteValve.class); >+ > static { > /* > * Replicates httpd's encoding >@@ -155,12 +165,10 @@ > context = true; > is = ((Context) getContainer()).getServletContext() > .getResourceAsStream("/WEB-INF/" + resourcePath); >- if (container.getLogger().isDebugEnabled()) { > if (is == null) { >- container.getLogger().debug("No configuration resource found: /WEB-INF/" + resourcePath); >+ log.info("No configuration resource found: /WEB-INF/" + resourcePath); > } else { >- container.getLogger().debug("Read configuration from: /WEB-INF/" + resourcePath); >- } >+ log.info("Read configuration from: /WEB-INF/" + resourcePath); > } > } else if (getContainer() instanceof Host) { > String resourceName = getHostConfigPath(resourcePath); >@@ -170,21 +178,19 @@ > // 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) { >+ log.info("Read configuration from CL at " + resourceName); > } > } else { >- if (container.getLogger().isDebugEnabled()) { >- container.getLogger().debug("Read configuration from " + file.getAbsolutePath()); >- } >+ log.info("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) { >+ log.info("No configuration resource found: " + resourceName + > " in " + getConfigBase() + " or in the classloader"); > } > } catch (Exception e) { >- container.getLogger().error("Error opening configuration", e); >+ log.error("Error opening configuration", e); > } > } > >@@ -197,12 +203,12 @@ > BufferedReader reader = new BufferedReader(isr)) { > parse(reader); > } catch (IOException ioe) { >- container.getLogger().error("Error closing configuration", ioe); >+ log.error("Error closing configuration", ioe); > } finally { > try { > is.close(); > } catch (IOException e) { >- container.getLogger().error("Error closing configuration", e); >+ log.error("Error closing configuration", e); > } > } > >@@ -213,6 +219,11 @@ > maps.clear(); > parse(new BufferedReader(new StringReader(configuration))); > } >+ >+ private long getRewriteTime(long startTime) >+ { >+ return System.currentTimeMillis() - startTime; >+ } > > public String getConfiguration() { > StringBuffer buffer = new StringBuffer(); >@@ -238,24 +249,20 @@ > 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() >+ log.info("Add rule with pattern " + rule.getPatternString() > + " and substitution " + rule.getSubstitutionString()); >- } > for (int i = (conditions.size() - 1); i > 0; i--) { > if (conditions.get(i - 1).isOrnext()) { > conditions.get(i).setOrnext(true); > } > } > for (int i = 0; i < conditions.size(); i++) { >- if (container.getLogger().isDebugEnabled()) { >- RewriteCond cond = conditions.get(i); >- container.getLogger().debug("Add condition " + cond.getCondPattern() >+ RewriteCond cond = conditions.get(i); >+ log.info("Add condition " + cond.getCondPattern() > + " test " + cond.getTestString() + " to rule with pattern " > + rule.getPatternString() + " and substitution " > + rule.getSubstitutionString() + (cond.isOrnext() ? " [OR]" : "") > + (cond.isNocase() ? " [NC]" : "")); >- } > rule.addCondition(conditions.get(i)); > } > conditions.clear(); >@@ -271,7 +278,7 @@ > } > } > } catch (IOException e) { >- container.getLogger().error("Error reading configuration", e); >+ log.error("Error reading configuration", e); > } > } > this.rules = rules.toArray(new RewriteRule[0]); >@@ -300,6 +307,7 @@ > @Override > public void invoke(Request request, Response response) > throws IOException, ServletException { >+ long start = System.currentTimeMillis(); > > if (!getEnabled() || rules == null || rules.length == 0) { > getNext().invoke(request, response); >@@ -325,6 +333,7 @@ > // converted to a string > String uriEncoding = request.getConnector().getURIEncoding(); > String originalQueryStringEncoded = request.getQueryString(); >+ String originalRequestURI = null; > MessageBytes urlMB = > context ? request.getRequestPathMB() : request.getDecodedRequestURIMB(); > urlMB.toChars(); >@@ -337,11 +346,13 @@ > RewriteRule rule = rules[i]; > CharSequence test = (rule.isHost()) ? host : urlDecoded; > CharSequence newtest = rule.evaluate(test, resolver); >+ if(log.isDebugEnabled()) >+ { >+ log.debug("applying pattern '"+rule.getPatternString()+"' to uri '"+test+"'"); >+ } > if (newtest != null && !test.equals(newtest.toString())) { >- if (container.getLogger().isDebugEnabled()) { >- container.getLogger().debug("Rewrote " + test + " as " + newtest >- + " with rule pattern " + rule.getPatternString()); >- } >+ originalRequestURI = test.toString(); >+ log.info("pattern '"+rule.getPatternString()+"' matches uri '"+test+"'"); > if (rule.isHost()) { > host = newtest; > } else { >@@ -564,6 +575,8 @@ > // This doesn't actually happen in the Catalina adapter implementation > } > } >+ log.info("Rewrote '" + originalRequestURI + "' -> '" + urlDecoded >+ + "' in "+getRewriteTime(start) + " ms "); > } else { > getNext().invoke(request, response); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 60161
:
34287
|
34290
|
34293