View | Details | Raw Unified | Return to bug 60161
Collapse All | Expand All

(-)java/org/apache/catalina/core/ContainerBase.java (-28 / +29 lines)
Lines 357-363 Link Here
357
357
358
        if (logger != null)
358
        if (logger != null)
359
            return (logger);
359
            return (logger);
360
        logger = LogFactory.getLog(logName());
360
        logger = LogFactory.getLog(getLogName());
361
        return (logger);
361
        return (logger);
362
362
363
    }
363
    }
Lines 364-369 Link Here
364
364
365
365
366
    /**
366
    /**
367
     * @return the abbreviated name of this container for logging messages
368
     */
369
    @Override
370
    public String getLogName() {
371
372
        if (logName != null) {
373
            return logName;
374
        }
375
        String loggerName = null;
376
        Container current = this;
377
        while (current != null) {
378
            String name = current.getName();
379
            if ((name == null) || (name.equals(""))) {
380
                name = "/";
381
            } else if (name.startsWith("##")) {
382
                name = "/" + name;
383
            }
384
            loggerName = "[" + name + "]"
385
                + ((loggerName != null) ? ("." + loggerName) : "");
386
            current = current.getParent();
387
        }
388
        logName = ContainerBase.class.getName() + "." + loggerName;
389
        return logName;
390
391
    }
392
393
394
    /**
367
     * Return the Cluster with which this Container is associated.  If there is
395
     * Return the Cluster with which this Container is associated.  If there is
368
     * no associated Cluster, return the Cluster associated with our parent
396
     * no associated Cluster, return the Cluster associated with our parent
369
     * Container (if any); otherwise return <code>null</code>.
397
     * Container (if any); otherwise return <code>null</code>.
Lines 1183-1215 Link Here
1183
    }
1211
    }
1184
1212
1185
1213
1186
    /**
1187
     * @return the abbreviated name of this container for logging messages
1188
     */
1189
    protected String logName() {
1190
1191
        if (logName != null) {
1192
            return logName;
1193
        }
1194
        String loggerName = null;
1195
        Container current = this;
1196
        while (current != null) {
1197
            String name = current.getName();
1198
            if ((name == null) || (name.equals(""))) {
1199
                name = "/";
1200
            } else if (name.startsWith("##")) {
1201
                name = "/" + name;
1202
            }
1203
            loggerName = "[" + name + "]"
1204
                + ((loggerName != null) ? ("." + loggerName) : "");
1205
            current = current.getParent();
1206
        }
1207
        logName = ContainerBase.class.getName() + "." + loggerName;
1208
        return logName;
1209
1210
    }
1211
1212
1213
    // -------------------- JMX and Registration  --------------------
1214
    // -------------------- JMX and Registration  --------------------
1214
1215
1215
    @Override
1216
    @Override
(-)java/org/apache/catalina/valves/rewrite/RewriteValve.java (-19 / +28 lines)
Lines 47-52 Link Here
47
import org.apache.catalina.connector.Response;
47
import org.apache.catalina.connector.Response;
48
import org.apache.catalina.util.URLEncoder;
48
import org.apache.catalina.util.URLEncoder;
49
import org.apache.catalina.valves.ValveBase;
49
import org.apache.catalina.valves.ValveBase;
50
import org.apache.juli.logging.LogFactory;
50
import org.apache.tomcat.util.buf.CharChunk;
51
import org.apache.tomcat.util.buf.CharChunk;
51
import org.apache.tomcat.util.buf.MessageBytes;
52
import org.apache.tomcat.util.buf.MessageBytes;
52
import org.apache.tomcat.util.buf.UriUtil;
53
import org.apache.tomcat.util.buf.UriUtil;
Lines 143-149 Link Here
143
        this.enabled = enabled;
144
        this.enabled = enabled;
144
    }
145
    }
145
146
147
146
    @Override
148
    @Override
149
    protected void initInternal() throws LifecycleException {
150
        super.initInternal();
151
        containerLog = LogFactory.getLog(getContainer().getLogName() + ".rewrite");
152
    }
153
154
155
    @Override
147
    protected synchronized void startInternal() throws LifecycleException {
156
    protected synchronized void startInternal() throws LifecycleException {
148
157
149
        super.startInternal();
158
        super.startInternal();
Lines 155-165 Link Here
155
            context = true;
164
            context = true;
156
            is = ((Context) getContainer()).getServletContext()
165
            is = ((Context) getContainer()).getServletContext()
157
                .getResourceAsStream("/WEB-INF/" + resourcePath);
166
                .getResourceAsStream("/WEB-INF/" + resourcePath);
158
            if (container.getLogger().isDebugEnabled()) {
167
            if (containerLog.isDebugEnabled()) {
159
                if (is == null) {
168
                if (is == null) {
160
                    container.getLogger().debug("No configuration resource found: /WEB-INF/" + resourcePath);
169
                    containerLog.debug("No configuration resource found: /WEB-INF/" + resourcePath);
161
                } else {
170
                } else {
162
                    container.getLogger().debug("Read configuration from: /WEB-INF/" + resourcePath);
171
                    containerLog.debug("Read configuration from: /WEB-INF/" + resourcePath);
163
                }
172
                }
164
            }
173
            }
165
        } else if (getContainer() instanceof Host) {
174
        } else if (getContainer() instanceof Host) {
Lines 170-190 Link Here
170
                    // Use getResource and getResourceAsStream
179
                    // Use getResource and getResourceAsStream
171
                    is = getClass().getClassLoader()
180
                    is = getClass().getClassLoader()
172
                        .getResourceAsStream(resourceName);
181
                        .getResourceAsStream(resourceName);
173
                    if (is != null && container.getLogger().isDebugEnabled()) {
182
                    if (is != null && containerLog.isDebugEnabled()) {
174
                        container.getLogger().debug("Read configuration from CL at " + resourceName);
183
                        containerLog.debug("Read configuration from CL at " + resourceName);
175
                    }
184
                    }
176
                } else {
185
                } else {
177
                    if (container.getLogger().isDebugEnabled()) {
186
                    if (containerLog.isDebugEnabled()) {
178
                        container.getLogger().debug("Read configuration from " + file.getAbsolutePath());
187
                        containerLog.debug("Read configuration from " + file.getAbsolutePath());
179
                    }
188
                    }
180
                    is = new FileInputStream(file);
189
                    is = new FileInputStream(file);
181
                }
190
                }
182
                if ((is == null) && (container.getLogger().isDebugEnabled())) {
191
                if ((is == null) && (containerLog.isDebugEnabled())) {
183
                    container.getLogger().debug("No configuration resource found: " + resourceName +
192
                    containerLog.debug("No configuration resource found: " + resourceName +
184
                            " in " + getConfigBase() + " or in the classloader");
193
                            " in " + getConfigBase() + " or in the classloader");
185
                }
194
                }
186
            } catch (Exception e) {
195
            } catch (Exception e) {
187
                container.getLogger().error("Error opening configuration", e);
196
                containerLog.error("Error opening configuration", e);
188
            }
197
            }
189
        }
198
        }
190
199
Lines 197-208 Link Here
197
                BufferedReader reader = new BufferedReader(isr)) {
206
                BufferedReader reader = new BufferedReader(isr)) {
198
            parse(reader);
207
            parse(reader);
199
        } catch (IOException ioe) {
208
        } catch (IOException ioe) {
200
            container.getLogger().error("Error closing configuration", ioe);
209
            containerLog.error("Error closing configuration", ioe);
201
        } finally {
210
        } finally {
202
            try {
211
            try {
203
                is.close();
212
                is.close();
204
            } catch (IOException e) {
213
            } catch (IOException e) {
205
                container.getLogger().error("Error closing configuration", e);
214
                containerLog.error("Error closing configuration", e);
206
            }
215
            }
207
        }
216
        }
208
217
Lines 238-245 Link Here
238
                Object result = parse(line);
247
                Object result = parse(line);
239
                if (result instanceof RewriteRule) {
248
                if (result instanceof RewriteRule) {
240
                    RewriteRule rule = (RewriteRule) result;
249
                    RewriteRule rule = (RewriteRule) result;
241
                    if (container.getLogger().isDebugEnabled()) {
250
                    if (containerLog.isDebugEnabled()) {
242
                        container.getLogger().debug("Add rule with pattern " + rule.getPatternString()
251
                        containerLog.debug("Add rule with pattern " + rule.getPatternString()
243
                                + " and substitution " + rule.getSubstitutionString());
252
                                + " and substitution " + rule.getSubstitutionString());
244
                    }
253
                    }
245
                    for (int i = (conditions.size() - 1); i > 0; i--) {
254
                    for (int i = (conditions.size() - 1); i > 0; i--) {
Lines 248-256 Link Here
248
                        }
257
                        }
249
                    }
258
                    }
250
                    for (int i = 0; i < conditions.size(); i++) {
259
                    for (int i = 0; i < conditions.size(); i++) {
251
                        if (container.getLogger().isDebugEnabled()) {
260
                        if (containerLog.isDebugEnabled()) {
252
                            RewriteCond cond = conditions.get(i);
261
                            RewriteCond cond = conditions.get(i);
253
                            container.getLogger().debug("Add condition " + cond.getCondPattern()
262
                            containerLog.debug("Add condition " + cond.getCondPattern()
254
                                    + " test " + cond.getTestString() + " to rule with pattern "
263
                                    + " test " + cond.getTestString() + " to rule with pattern "
255
                                    + rule.getPatternString() + " and substitution "
264
                                    + rule.getPatternString() + " and substitution "
256
                                    + rule.getSubstitutionString() + (cond.isOrnext() ? " [OR]" : "")
265
                                    + rule.getSubstitutionString() + (cond.isOrnext() ? " [OR]" : "")
Lines 271-277 Link Here
271
                    }
280
                    }
272
                }
281
                }
273
            } catch (IOException e) {
282
            } catch (IOException e) {
274
                container.getLogger().error("Error reading configuration", e);
283
                containerLog.error("Error reading configuration", e);
275
            }
284
            }
276
        }
285
        }
277
        this.rules = rules.toArray(new RewriteRule[0]);
286
        this.rules = rules.toArray(new RewriteRule[0]);
Lines 338-345 Link Here
338
                CharSequence test = (rule.isHost()) ? host : urlDecoded;
347
                CharSequence test = (rule.isHost()) ? host : urlDecoded;
339
                CharSequence newtest = rule.evaluate(test, resolver);
348
                CharSequence newtest = rule.evaluate(test, resolver);
340
                if (newtest != null && !test.equals(newtest.toString())) {
349
                if (newtest != null && !test.equals(newtest.toString())) {
341
                    if (container.getLogger().isDebugEnabled()) {
350
                    if (containerLog.isDebugEnabled()) {
342
                        container.getLogger().debug("Rewrote " + test + " as " + newtest
351
                        containerLog.debug("Rewrote " + test + " as " + newtest
343
                                + " with rule pattern " + rule.getPatternString());
352
                                + " with rule pattern " + rule.getPatternString());
344
                    }
353
                    }
345
                    if (rule.isHost()) {
354
                    if (rule.isHost()) {
(-)java/org/apache/catalina/Container.java (+7 lines)
Lines 123-128 Link Here
123
123
124
124
125
    /**
125
    /**
126
     * Return the logger name that the container will use.
127
     * @return the abbreviated name of this container for logging messages
128
     */
129
    public String getLogName();
130
131
132
    /**
126
     * Obtain the JMX name for this container.
133
     * Obtain the JMX name for this container.
127
     *
134
     *
128
     * @return the JMX name associated with this container.
135
     * @return the JMX name associated with this container.

Return to bug 60161