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

TomcatLoggingSupport

public class TomcatLoggingSupport extends Object implements com.sun.enterprise.server.pluggable.LoggingSupport
Support for logging features when used with http engine from tomcat.

Fields Summary
private static String
defaultLogFileName
private static String
logFileName
private static FileHandler
fHandler
private static final String
LOGS_DIR
private static final String
LOG_FILE
Constructors Summary
Methods Summary
public java.util.logging.HandlercreateLogHandler()
Create a log handler object.


              
       
        String fileName = getLogFileName();
        Handler h = null;
        try {
	    if (fHandler == null) {
                fHandler = new FileHandler(fileName, true);
	    }
        } catch (Exception e) {
            // If there is an exception in creation of file handler,
            // use a console handler instead.
            // NOI18N
            System.err.println("Error creating log handler for " + fileName
                    + ". Using ConsoleHandler -- " + e.getMessage());
            e.printStackTrace();
            h = new ConsoleHandler();
	    return h;
        }

	h = fHandler;
        return h;
    
private static java.lang.StringgetDefaultLogFileName()
Get default log file name.

        if (defaultLogFileName == null) {
            ServerContext sc = ApplicationServer.getServerContext();
            String instDir;
            if (sc != null) {
                instDir = sc.getInstanceEnvironment().getInstancesRoot();
            } else {
                // FIX: Use some other system property before user.dir
                instDir = System.getProperty("user.dir");
            }
            String[] names = {instDir, LOGS_DIR, LOG_FILE};
            defaultLogFileName = StringUtils.makeFilePath(names, false);
        }
        return defaultLogFileName;
    
private static java.lang.StringgetLogFileName()
Get log file name. If a log file name is defined in configuration then the method returns that value, otherwise it returns default log file name.

        if (logFileName == null) {
            ServerContext sc = ApplicationServer.getServerContext();
            if (sc != null) {
                ConfigContext ctx = sc.getConfigContext();
                LogService ls = null;
                try {
                    ls = ServerBeansFactory.getConfigBean(ctx).getLogService();
                } catch (ConfigException ce) {
                    // Ignore this exception, intent is to use default file
                    // NOI18N
                    System.err.println("Error accessing log service config -- "
                            + ce.getMessage() + "\nUsing default file");
                    ce.printStackTrace();
                }
                if (ls != null) {
                    logFileName = ls.getFile();
                }
            }
        }
        if (logFileName != null) {
            return logFileName;
        } else {
            return getDefaultLogFileName();
        }