Bug 58905

Summary: Fix Tomcat.silence() to silence the correct logger and to respect defaults
Product: Tomcat 9 Reporter: Konstantin Kolinko <knst.kolinko>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: minor    
Priority: P2    
Version: unspecified   
Target Milestone: -----   
Hardware: PC   
OS: All   

Description Konstantin Kolinko 2016-01-21 21:23:24 UTC
Noted when reviewing implementation of Tomcat.silence() in relation to Tomcat unit tests.

Currently Tomcat.addContext() is implemented as following:
[[[
    public Context addContext(Host host, String contextPath, String contextName,
            String dir) {
        silence(host, contextPath);
        Context ctx = createContext(host, contextPath);
        ctx.setName(contextName);
        ctx.setPath(contextPath);
        ctx.setDocBase(dir);
        ctx.addLifecycleListener(new FixContextListener());

        if (host == null) {
            getHost().addChild(ctx);
        } else {
            host.addChild(ctx);
        }
        return ctx;
    }
]]]

The silence() call attempts to silence the logger for this Context by setting its log level to Level.WARNING.

The following notes apply to Tomcat class of all current versions
(Tomcat 7/8/9):

1. Note that in Tomcat unit tests the loggers are not silenced by default,
as Tomcat.setSilent(boolean) is not called by Tomcat test code.

=> The silent(Host, contextPath) call shall respect the defaults and do not silence this logger if other loggers are not silenced.

2. The Engine name used in Tomcat.getLoggerName() is wrong.

Tomcat.getEngine() uses "Tomcat" as the name, not "default".

=> It shall get the actual Engine instance from Host.getParent().

3. Tomcat.getLoggerName() shall use the same logic as ContainerBase.logName()

=> It does not handle "" and null names correctly.
Comment 1 Mark Thomas 2016-02-01 10:45:31 UTC
Fixed in 9.0.x for 9.0.0.M3 onwards.
Comment 2 Mark Thomas 2016-02-02 00:36:09 UTC
Fixed in 8.0.x for 8.0.32 onwards.
Comment 3 Mark Thomas 2016-02-02 19:52:19 UTC
Fixed in 7.0.x for 7.0.68 onwards.