~ubuntu-branches/ubuntu/natty/tomcat6/natty-proposed

« back to all changes in this revision

Viewing changes to java/org/apache/juli/ClassLoaderLogManager.java

  • Committer: Bazaar Package Importer
  • Author(s): Thierry Carrez
  • Date: 2010-05-21 13:51:15 UTC
  • mfrom: (2.2.12 sid)
  • Revision ID: james.westby@ubuntu.com-20100521135115-qfwnf24lzvi3644v
Tags: 6.0.26-2
* debian/tomcat6.{postinst,prerm}: Respect TOMCAT6_USER and TOMCAT6_GROUP
  as defined in /etc/default/tomcat6 when setting directory permissions and
  authbind configuration (Closes: #581018, LP: #557300)
* debian/tomcat6.postinst: Use group "tomcat6" instead of "adm" for
  permissions in /var/lib/tomcat6, so that group "adm" doesn't get write
  permissions over /var/lib/tomcat6/webapps (LP: #569118)

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
        
51
51
        @Override
52
52
        public void run() {
53
 
            // The JVM us being shutdown. Make sure all loggers for all class
54
 
            // loaders are shutdown
55
 
            for (ClassLoaderLogInfo clLogInfo : classLoaderLoggers.values()) {
56
 
                for (Logger logger : clLogInfo.loggers.values()) {
57
 
                    resetLogger(logger);
58
 
                }
59
 
            }
60
 
        }
61
 
            
62
 
        private void resetLogger(Logger logger) {
63
 
            
64
 
            Handler[] handlers = logger.getHandlers();
65
 
            for (Handler handler : handlers) {
66
 
                logger.removeHandler(handler);
67
 
                try {
68
 
                    handler.close();
69
 
                } catch (Exception e) {
70
 
                    // Ignore
71
 
                }
 
53
            if (useShutdownHook) {
 
54
                shutdown();
72
55
            }
73
56
        }
74
57
 
105
88
     */
106
89
    protected ThreadLocal<String> prefix = new ThreadLocal<String>();
107
90
 
 
91
 
 
92
    /**
 
93
     * Determines if the shutdown hook is used to perform any necessary
 
94
     * clean-up such as flushing buffered handlers on JVM shutdown. Defaults to
 
95
     * <code>true</code> but may be set to false if another component ensures
 
96
     * that {@link #shutdown()} is called.
 
97
     */
 
98
    protected volatile boolean useShutdownHook = true;
 
99
 
108
100
    
 
101
    // ------------------------------------------------------------- Properties
 
102
 
 
103
 
 
104
    public boolean isUseShutdownHook() {
 
105
        return useShutdownHook;
 
106
    }
 
107
 
 
108
 
 
109
    public void setUseShutdownHook(boolean useShutdownHook) {
 
110
        this.useShutdownHook = useShutdownHook;
 
111
    }
 
112
 
 
113
 
109
114
    // --------------------------------------------------------- Public Methods
110
115
 
111
116
 
291
296
        readConfiguration(is, Thread.currentThread().getContextClassLoader());
292
297
    
293
298
    }
294
 
        
 
299
 
 
300
    @Override
 
301
    public void reset() throws SecurityException {
 
302
        Thread thread = Thread.currentThread();
 
303
        if (thread.getClass().getName().startsWith(
 
304
                "java.util.logging.LogManager$")) {
 
305
            // Ignore the call from java.util.logging.LogManager.Cleaner,
 
306
            // because we have our own shutdown hook
 
307
            return;
 
308
        }
 
309
        ClassLoader classLoader = thread.getContextClassLoader();
 
310
        ClassLoaderLogInfo clLogInfo = getClassLoaderInfo(classLoader);
 
311
        resetLoggers(clLogInfo);
 
312
        super.reset();
 
313
    }
 
314
 
 
315
    /**
 
316
     * Shuts down the logging system.
 
317
     */
 
318
    public void shutdown() {
 
319
        // The JVM us being shutdown. Make sure all loggers for all class
 
320
        // loaders are shutdown
 
321
        for (ClassLoaderLogInfo clLogInfo : classLoaderLoggers.values()) {
 
322
            resetLoggers(clLogInfo);
 
323
        }
 
324
    }
 
325
 
 
326
    // -------------------------------------------------------- Private Methods
 
327
    private void resetLoggers(ClassLoaderLogInfo clLogInfo) {
 
328
        // This differs from LogManager#resetLogger() in that we close not all
 
329
        // handlers of all loggers, but only those that are present in our
 
330
        // ClassLoaderLogInfo#handlers list. That is because our #addLogger(..)
 
331
        // method can use handlers from the parent class loaders, and closing
 
332
        // handlers that the current class loader does not own would be not
 
333
        // good.
 
334
        synchronized (clLogInfo) {
 
335
            for (Logger logger : clLogInfo.loggers.values()) {
 
336
                Handler[] handlers = logger.getHandlers();
 
337
                for (Handler handler : handlers) {
 
338
                    logger.removeHandler(handler);
 
339
                }
 
340
            }
 
341
            for (Handler handler : clLogInfo.handlers.values()) {
 
342
                try {
 
343
                    handler.close();
 
344
                } catch (Exception e) {
 
345
                    // Ignore
 
346
                }
 
347
            }
 
348
            clLogInfo.handlers.clear();
 
349
        }
 
350
    }
 
351
 
295
352
    // ------------------------------------------------------ Protected Methods
296
353
 
297
354