Search in sources :

Example 1 with AcsLoggingHandler

use of alma.acs.logging.AcsLoggingHandler in project ACS by ACS-Community.

the class TestLogLevelsCompImpl method getLevels.

/////////////////////////////////////////////////////////////
// Implementation of TestLogLevelsCompOperations
/////////////////////////////////////////////////////////////
public int[] getLevels() throws CouldntPerformActionEx {
    //m_logger.info("getLevels called...");
    /*
    	 *  alma.maci.loggingconfig.LoggingConfig got generated from LoggingConfig.xsd and
    	 *  it contains the "default values" (also called "hardcoded").
    	 */
    levels = new int[5];
    LoggingConfig logConfig = new LoggingConfig();
    int hcMinLogLevel = Integer.parseInt(logConfig.getMinLogLevel().toString());
    int hcMinLogLevelLocal = Integer.parseInt(logConfig.getMinLogLevelLocal().toString());
    AcsLogLevel acsLevel = AcsLogLevel.getNativeLevel(m_logger.getLevel());
    int acsCoreLevel = acsLevel.getAcsLevel().value;
    // get separately the stdout and remote levels
    Handler[] handlers = m_logger.getHandlers();
    if (handlers.length != 2) {
        AcsJCouldntPerformActionEx ex = new AcsJCouldntPerformActionEx();
        ex.setProperty(PROP_ASSERTION_MESSAGE, "Found " + handlers.length + " log handlers where 2 were expected.");
        throw ex.toCouldntPerformActionEx();
    //m_logger.info("Found " + handlers.length + " log handlers where 2 were expected.");
    }
    AcsLogLevel levelStdout = null;
    AcsLogLevel levelRemote = null;
    for (Handler logHandler : handlers) {
        if (logHandler instanceof StdOutConsoleHandler) {
            levelStdout = AcsLogLevel.getNativeLevel(logHandler.getLevel());
        } else if (logHandler instanceof AcsLoggingHandler) {
            levelRemote = AcsLogLevel.getNativeLevel(logHandler.getLevel());
        } else {
            AcsJCouldntPerformActionEx ex = new AcsJCouldntPerformActionEx();
            ex.setProperty(PROP_ASSERTION_MESSAGE, "Handler " + logHandler + " is neither StdOutConsoleHandler nor AcsLoggingHandler");
            throw ex.toCouldntPerformActionEx();
        }
    }
    levels[0] = hcMinLogLevel;
    levels[1] = hcMinLogLevelLocal;
    levels[2] = acsCoreLevel;
    if (// should never be the case, but anyway ...
    levelRemote == null)
        levels[3] = -1;
    else
        levels[3] = levelRemote.getAcsLevel().value;
    if (// should never be the case, but anyway ...
    levelStdout == null)
        levels[4] = -1;
    else
        levels[4] = levelStdout.getAcsLevel().value;
    return levels;
}
Also used : AcsLogLevel(alma.acs.logging.AcsLogLevel) AcsJCouldntPerformActionEx(alma.ACSErrTypeCommon.wrappers.AcsJCouldntPerformActionEx) LoggingConfig(alma.maci.loggingconfig.LoggingConfig) StdOutConsoleHandler(alma.acs.logging.StdOutConsoleHandler) AcsLoggingHandler(alma.acs.logging.AcsLoggingHandler) AcsLoggingHandler(alma.acs.logging.AcsLoggingHandler) StdOutConsoleHandler(alma.acs.logging.StdOutConsoleHandler) Handler(java.util.logging.Handler)

Aggregations

AcsJCouldntPerformActionEx (alma.ACSErrTypeCommon.wrappers.AcsJCouldntPerformActionEx)1 AcsLogLevel (alma.acs.logging.AcsLogLevel)1 AcsLoggingHandler (alma.acs.logging.AcsLoggingHandler)1 StdOutConsoleHandler (alma.acs.logging.StdOutConsoleHandler)1 LoggingConfig (alma.maci.loggingconfig.LoggingConfig)1 Handler (java.util.logging.Handler)1