FileDocCategorySizeDatePackage
ACCLogManager.javaAPI DocGlassfish v2 API6578Fri May 04 22:35:44 BST 2007com.sun.enterprise.server.logging

ACCLogManager

public class ACCLogManager extends BaseLogManager
Class ACCLogManager is intended for use in the Application Client Container. The sun-acc.xml file holds ACC configuration as well as logging configuration including log file name and log level. The FileHandler is installed as the only logging handler.

Fields Summary
private final String
CLIENT_XML_FULL_NAME
private final String
DEFAULT_CLIENT_CONTAINER_XML
private Handler
_clientHandler
private Level
_logLevel
private boolean
initialized
Constructors Summary
public ACCLogManager()


      
        super();
    
Methods Summary
public synchronized voidinit(java.lang.String configFile)


        if (initialized) return;
        initialized = true;

        try {
            ConfigContext ctx =
                ConfigFactory.createConfigContext
                (configFile, true, false, false,
                 com.sun.enterprise.config.clientbeans.ClientContainer.class,
		 new com.sun.enterprise.config.clientbeans.ClientBeansResolver());
            final ClientContainer cc  =
                ClientBeansFactory.getClientBean(ctx);

            String logLevel = cc.getLogService().getLevel();
            if (logLevel != null && !logLevel.equals("")) {
                _logLevel = Level.parse(logLevel);
            }
            
            String logFileName = cc.getLogService().getFile();
            if (logFileName != null && !logFileName.equals("")) {
                _clientHandler = new FileHandler(logFileName, true);
                _clientHandler.setFormatter(new SimpleFormatter());
                
                // workaround to delete lockfile upon exit
                File lockFile = new File(logFileName + ".lck");
                lockFile.deleteOnExit();
            }
            
        } catch (Exception ex) {
            if (_logger != null) {
                _logger.logrb(Level.SEVERE, null, null,
                              "com.sun.logging.enterprise.system.container.appclient.LogStrings",
                              "acc.cannot_create_log_handler", ex);
            }
        }

        // Previously registered loggers need to be
        // modified to use the right handler and set the
        // the right level.
        Enumeration e = getLoggerNames();
        while (e.hasMoreElements()) {
            String loggerName = (String) e.nextElement();
            Logger l = getLogger(loggerName);
            initializeLogger(l);
        }
    
protected synchronized voidinitializeLogger(java.util.logging.Logger l)

        java.security.AccessController.doPrivileged(
            new java.security.PrivilegedAction() {
                public Object run() {

                    l.setLevel(_logLevel);

                    // only if using file handler
                    if (_clientHandler != null) {
                        // Explicitely remove all handlers. 
                        Handler[] h = l.getHandlers();
                        for (int i = 0; i < h.length; i++) {
                            l.removeHandler(h[i]);
                        }
                        
                        l.setUseParentHandlers(false);
                        
                        // Install handler and formatter. All other handlers are removed 
                        // intentionally. In theory setUseParentHandlers(false) should do
                        // the same thing, but there are subtle differences (again related 
                        // to static init) that was causing duplicate output in the log.
                        l.addHandler(_clientHandler);
                    }
                    return null;
                }
            }
        );