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

ModuleToLoggerNameMapper

public class ModuleToLoggerNameMapper extends Object
A Simple No Brainer Utility to map the Module Name to Logger Name..
author
Hemanth Puttaswamy

Fields Summary
private static Object[]
ModuleAndLoggerTable
Constructors Summary
Methods Summary
public static java.lang.String[]getLoggerNames(java.lang.String moduleName)

moduleName
the log module name (eg. "admin"); if null, it means all modules.
return
the logger names for this module; size of returned String[] >=1.

        ArrayList result = new ArrayList(); 
        for (int i=0; i<ModuleAndLoggerTable.length; i++) {
            Object[] dim = ModuleAndLoggerTable[i];
            String   modName = (String)dim[0];
            String[] loggerNames = (String[]) dim[1];
            if (loggerNames!=null) {
                if (moduleName == null) {  //we return all AS module loggers in this case
		    result.addAll(Arrays.asList(loggerNames) ); 
                } else if (moduleName.equals(modName)) {
                    result.addAll( Arrays.asList(loggerNames) );
                    break;
                }
	    }
        }
        String[] lNames = new String[ result.size()];
        return (String[])result.toArray(lNames);
    
public static java.lang.StringgetMatchedModuleLoggerName(java.lang.String loggerName)

loggername
the logname (could be the name of a child logger of a module logger)
return
the module logger name.

        for (int i=0; i<ModuleAndLoggerTable.length; i++) {
            Object[] dim = ModuleAndLoggerTable[i];
            String[] loggerNames = (String[]) dim[1];            
            for (int j=0; loggerNames!=null && j<loggerNames.length;j++) {
                String name=loggerNames[j];
                if (loggerName.startsWith(name) )
                    return name;
            }
        }
        
        try {
            ServerContext sc = ApplicationServer.getServerContext();        
            if (sc!=null)  {
                Config cfg = ServerBeansFactory.getConfigBean(sc.getConfigContext());
                ModuleLogLevels allModulesLogLevels = cfg.getLogService().getModuleLogLevels( );
                ElementProperty[] elementProperties = allModulesLogLevels.getElementProperty( );
                if( elementProperties != null ) {
                    for( int i = 0; i < elementProperties.length; i++ ) {
                        String name = elementProperties[i].getName();
                        if( loggerName.startsWith(name)) {
                            return name;
                        }
                    }
                }            
            }
        } catch ( Exception e ) {
            new ErrorManager().error( "Error In Setting Initial Loglevel", e,
                ErrorManager.GENERIC_FAILURE );
        }        
        return null;
    
public static java.lang.StringgetModuleName(java.lang.String loggerName)

loggername
the logname
return
the module name the logger is for.

    

                      
         
        for (int i=0; i<ModuleAndLoggerTable.length; i++) {
            Object[] dim = ModuleAndLoggerTable[i];
            String   modName = (String)dim[0];
            String[] loggerNames = (String[]) dim[1];            
            for (int j=0; loggerNames!=null && j<loggerNames.length;j++) {
                String name=loggerNames[j];
                if (loggerName.equals(name))
                    return modName;
            }
        }
        return null;