Search in sources :

Example 1 with StdOutConsoleHandler

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

the class ShutdownHookTest method main.

/**
	 * Creates the ComponentClient "ShutdownHookTestClient" and tests its cleanup
	 * using calls to tearDown coming both from the shutdown hook and from explicit invocations.
	 * <p>
	 * In the <code>tearDown</code> method, it enables FINE logs for stdout 
	 * before calling {@link ComponentClient#tearDown()},
	 * in order to not miss the "duplicate call" log that the base class creates 
	 * if <code>tearDown</code> is called more than once.
	 * <p>
	 * Meaning of the 3 int args:
	 * <ol>
	 *   <li> <code>0</code>: tearDown calls super.tearDown and exits. <br>
	 *        <code>!=0</code>: tearDown sleeps 10 seconds after calling super.tearDown
	 *   <li> Sleep time in seconds after creating the ComponentClient, before returning from this main method call.
	 *   <li> Number of additional calls to the ComponentClient's tearDown method.
	 * </ol>
	 * @param args
	 * @throws Exception
	 */
public static void main(String[] args) throws Exception {
    AcsLogger logger;
    ComponentClient m_client;
    logger = ClientLogManager.getAcsLogManager().getLoggerForApplication("ShutdownHookTestClient", false);
    if (Integer.parseInt(args[0]) == 0)
        m_client = new ComponentClient(logger, AcsLocations.figureOutManagerLocation(), "ShutdownHookTestClient") {

            public void tearDown() throws Exception {
                for (Handler h : m_logger.getHandlers()) {
                    if (h instanceof StdOutConsoleHandler) {
                        // to get the "duplicate call" log
                        h.setLevel(Level.FINE);
                    }
                }
                super.tearDown();
            }
        };
    else
        m_client = new ComponentClient(logger, AcsLocations.figureOutManagerLocation(), "ShutdownHookTestClient") {

            public void tearDown() throws Exception {
                for (Handler h : m_logger.getHandlers()) if (h instanceof StdOutConsoleHandler) {
                    // to get the "duplicate call" log
                    h.setLevel(Level.FINE);
                }
                super.tearDown();
                Thread.sleep(10 * 1000);
            }
        };
    // Sleep a little bit... depending on the amount of time, we might want to kill
    // this baby from the outside, who knows
    Thread.sleep(Integer.parseInt(args[1]) * 1000);
    // We may want to call tearDown() as many times as we want
    int iterations = Integer.parseInt(args[2]);
    for (int i = 0; i != iterations; i++) {
        m_client.tearDown();
    }
}
Also used : StdOutConsoleHandler(alma.acs.logging.StdOutConsoleHandler) StdOutConsoleHandler(alma.acs.logging.StdOutConsoleHandler) Handler(java.util.logging.Handler) AcsLogger(alma.acs.logging.AcsLogger)

Example 2 with StdOutConsoleHandler

use of alma.acs.logging.StdOutConsoleHandler 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

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