Search in sources :

Example 16 with LogConfig

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

the class AcsLoggingHandlerTest method setUp.

protected void setUp() {
    logQueue = new TestLogQueue();
    LogConfig logConfig = new LogConfig();
    loggingHandler = new AcsLoggingHandler(logQueue, logConfig, "dummyLoggerNameForHandlerLevelConfig", null);
}
Also used : LogConfig(alma.acs.logging.config.LogConfig)

Example 17 with LogConfig

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

the class LogThrottleTest method _testRealLogs.

public void _testRealLogs(int numLoops) {
    // instead of usual static method getAcsLogManager()
    TestClientLogManager clientLogManager = new TestClientLogManager();
    Logger logger = clientLogManager.getLoggerForApplication(getName(), true);
    LogConfig logConfig = clientLogManager.getLogConfig();
    AcsLogLevelDefinition remoteLevel = AcsLogLevelDefinition.CRITICAL;
    logConfig.setDefaultMinLogLevel(remoteLevel);
    logConfig.setDefaultMinLogLevelLocal(AcsLogLevelDefinition.TRACE);
    // the set of all levels used for ACS java logging (omitting JDK levels that have the same numerical value as a matching ACS level)
    Set<Level> levels = new HashSet<Level>();
    for (AcsLogLevelDefinition levelEnum : AcsLogLevelDefinition.values()) {
        if (levelEnum != AcsLogLevelDefinition.OFF) {
            levels.add(AcsLogLevel.fromAcsCoreLevel(levelEnum));
        }
    }
    levels.addAll(Arrays.asList(new Level[] { Level.FINEST, Level.FINER, Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE }));
    int numLoggableRemoteLevels = 1;
    AcsLogLevelDefinition tmpLevel = remoteLevel;
    while (tmpLevel.getNextHigherLevel() != null) {
        tmpLevel = tmpLevel.getNextHigherLevel();
        numLoggableRemoteLevels++;
    }
    int expectedNumberOfLocalLogs = levels.size();
    int expectedNumberOfRemoteLogs = Math.min(expectedNumberOfLocalLogs, numLoggableRemoteLevels * numLoops);
    // set throttle so that every log level should be logged once
    logConfig.setMaxLogsPerSecond(expectedNumberOfLocalLogs);
    System.out.println("Will log a burst of " + levels.size() * numLoops + " messages of various levels, setting the throttle to " + expectedNumberOfLocalLogs + " logs per second.");
    System.out.println("For stdout logs (level = TRACE) we expect " + expectedNumberOfLocalLogs + " logs, while for remote logs " + "(level = " + remoteLevel.name() + ") we expect " + expectedNumberOfRemoteLogs + " logs.");
    for (int i = 0; i < numLoops; i++) {
        for (Level level : levels) {
            logger.log(level, "test message with level " + level.getName());
        }
    }
    // verify the number of actual local logs
    assertEquals("Each log level should have produced only one local log.", expectedNumberOfLocalLogs, clientLogManager.getNumberLocalLogs());
    // The way this is constructed, the throttle should be active if numLoops > 1. 
    // Since no alarms are configured, we expect one warning log about the failure to raise a throttle alarm.
    int expectedAlarmErrorLogs = (numLoops > 1 ? 1 : 0);
    assertEquals("Bad number of throttle alarm error log(s)", expectedAlarmErrorLogs, clientLogManager.getNumberLocalThrottleAlarmErrorLogs());
    int numUserRemoteLogs = 0;
    for (LogRecord logRecord : clientLogManager.testLogQueue.logRecords) {
        if (!logRecord.getMessage().startsWith("Changed processName=")) {
            numUserRemoteLogs++;
        }
    }
    assertEquals("Wrong number of remote logs", expectedNumberOfRemoteLogs, numUserRemoteLogs);
}
Also used : LogRecord(java.util.logging.LogRecord) AcsLogLevelDefinition(alma.acs.logging.level.AcsLogLevelDefinition) Level(java.util.logging.Level) Logger(java.util.logging.Logger) LogConfig(alma.acs.logging.config.LogConfig) HashSet(java.util.HashSet)

Example 18 with LogConfig

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

the class LogThrottleTest method testSimulatedLogs.

/**
	 * Tests the LogThrottle class in isolation. 
	 * Many logs are simulated, over more than a second, to test also the re-opening of the throttle.
	 * Covers configuration without throttle, "total throttle" suppressing all logs, and "normal" throttling.
	 */
public void testSimulatedLogs() throws Exception {
    LogConfig logConfig = new LogConfig();
    TestThrottleCallback throttleCallback = new TestThrottleCallback();
    LogThrottle throttle = new LogThrottle(logConfig, throttleCallback);
    assertEquals(-1, logConfig.getMaxLogsPerSecond());
    System.out.println("Will simulate logging (above throttle limit), for little more than 2 seconds, which should suppress & clear logs twice.");
    int maxLogsPerSecond = 10;
    logConfig.setMaxLogsPerSecond(maxLogsPerSecond);
    assertEquals(maxLogsPerSecond, logConfig.getMaxLogsPerSecond());
    simulateLogging(throttle, 2100, 20, 2 * maxLogsPerSecond);
    Thread.sleep(1000);
    assertEquals(2, throttleCallback.getAndResetClearanceCounter());
    System.out.println("Will simulate logging without throttle set");
    logConfig.setMaxLogsPerSecond(-1);
    // normally ~100, but some machines are slow.
    simulateLogging(throttle, 2100, 20, 60);
    Thread.sleep(1000);
    assertEquals(0, throttleCallback.getAndResetClearanceCounter());
    System.out.println("Will simulate logging with degenerated throttle (all logs rejected)");
    logConfig.setMaxLogsPerSecond(0);
    simulateLogging(throttle, 2100, 10, 0);
    Thread.sleep(1000);
    assertEquals(0, throttleCallback.getAndResetClearanceCounter());
}
Also used : LogConfig(alma.acs.logging.config.LogConfig)

Example 19 with LogConfig

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

the class ClientLogManagerTest method testConfigureApplicationLogger.

/**
	 * As of ACS 8.1.0, it is not possible to configure application loggers via the CDB.
	 * This test demonstrates how to do it programmatically, as a workaround.
	 */
public void testConfigureApplicationLogger() {
    LogConfig sharedLogConfig = clientLogManager.getLogConfig();
    // Set default log levels before creating the application logger
    AcsLogLevelDefinition localLevel = AcsLogLevelDefinition.WARNING;
    AcsLogLevelDefinition remoteLevel = AcsLogLevelDefinition.CRITICAL;
    sharedLogConfig.setDefaultMinLogLevelLocal(localLevel);
    sharedLogConfig.setDefaultMinLogLevel(remoteLevel);
    // get the logger
    AcsLogger applLogger = clientLogManager.getLoggerForApplication("testApplicationLogger", true);
    // verify levels set on handlers
    assertLogLevels(applLogger, localLevel, remoteLevel);
    // change the default log levels
    localLevel = AcsLogLevelDefinition.INFO;
    remoteLevel = AcsLogLevelDefinition.TRACE;
    sharedLogConfig.setDefaultMinLogLevelLocal(localLevel);
    sharedLogConfig.setDefaultMinLogLevel(remoteLevel);
    assertLogLevels(applLogger, localLevel, remoteLevel);
    assertLogLevels(applLogger, localLevel, remoteLevel);
}
Also used : AcsLogLevelDefinition(alma.acs.logging.level.AcsLogLevelDefinition) LogConfig(alma.acs.logging.config.LogConfig)

Example 20 with LogConfig

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

the class ClientWithLogReceiverTest method testLogQueueNoDelay.

/**
     * Logs a single record and waits for it to come back from the Log service 
     * and to pass the queue (which is set to zero delay).
     * Then the record is verified, and the same test is repeated a couple of times with different log records. 
     * @throws Exception
     */
public void testLogQueueNoDelay() throws Exception {
    LogConfig logConfig = ClientLogManager.getAcsLogManager().getLogConfig();
    assertEquals("For this test, even low-level logs must be sent off remotely.", AcsLogLevelDefinition.TRACE, logConfig.getDefaultMinLogLevel());
    logReceiver.setDelayMillis(0);
    BlockingQueue<DelayedLogEntry> queue = logReceiver.getLogQueue();
    // the set of log levels to be randomly selected for the test logs 
    AcsLogLevelDefinition[] coreLevels = new AcsLogLevelDefinition[] { AcsLogLevelDefinition.TRACE, AcsLogLevelDefinition.DEBUG, AcsLogLevelDefinition.INFO, AcsLogLevelDefinition.WARNING, AcsLogLevelDefinition.EMERGENCY };
    int numberOfTestLogs = 10;
    Random random = new Random(System.currentTimeMillis());
    // loop for sending several test logs
    for (int i = 0; i < numberOfTestLogs; i++) {
        AcsLogLevelDefinition coreLevel = coreLevels[random.nextInt(coreLevels.length)];
        // TODO: using getLowestMatchingJdkLevel here may be temporary, see COMP-3925. 
        Level jdkLevel = AcsLogLevel.getLowestMatchingJdkLevel(coreLevel);
        // Log the test record
        String logMessage = "This is log number " + i;
        m_logger.log(jdkLevel, logMessage);
        // Wait for the test record to come back from the Log service.
        // In spite of zero queue sorting delay, we need a long timeout 
        // to compensate for travel delays to and from the Log service.
        // should be much less, but currently we have problems there.
        int delayLogServiceSec = 20;
        int timeoutSec = logConfig.getFlushPeriodSeconds() + delayLogServiceSec;
        long timeoutSysMillis = System.currentTimeMillis() + timeoutSec * 1000;
        while (true) {
            // System.currentTimeMillis() < timeoutSysMillis
            // wait on the queue for a log record to arrive
            DelayedLogEntry delayedLogEntry = queue.poll(timeoutSysMillis - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
            if (delayedLogEntry != null) {
                // got something, must check if it was the record we sent
                if (delayedLogEntry.isQueuePoison()) {
                    fail("Unexpected end of log queue.");
                }
                LogReceiver.ReceivedLogRecord logRecord = delayedLogEntry.getLogRecord();
                String sourceObjectName = logRecord.getSourceObject();
                if (sourceObjectName != null && sourceObjectName.equals("ClientWithLogReceiverTest#testLogQueueNoDelay") && !logRecord.getMessage().startsWith("------------ setUp") && !logRecord.getMessage().startsWith("Alarm system type:")) {
                    // it's a log record sent from this process 
                    assertEquals("Log message text must match the test log record", logMessage, logRecord.getMessage());
                    assertEquals("Log level must match the test log record", coreLevel, logRecord.getLevel().getAcsCoreLevel());
                    System.out.println("Received back log record #" + i);
                    // and continue outer loop with next log record
                    break;
                } else {
                    // was some other stray log, perhaps from a previously running ACS component, or the pinging jmanager
                    // we stay in the while loop and wait again for another record to be delivered by the queue
                    System.out.println(IsoDateFormat.formatCurrentDate() + ": Ignoring received log " + IsoDateFormat.formatDate(logRecord.getTimestamp()) + " [" + sourceObjectName + "]");
                }
            } else {
                fail("Did not receive the expected log record #" + i + " within " + timeoutSec + " seconds.");
            }
        }
    }
    logReceiver.stop();
}
Also used : Random(java.util.Random) AcsLogLevelDefinition(alma.acs.logging.level.AcsLogLevelDefinition) AcsLogLevel(alma.acs.logging.AcsLogLevel) Level(java.util.logging.Level) DelayedLogEntry(alma.acs.logging.engine.LogReceiver.DelayedLogEntry) LogConfig(alma.acs.logging.config.LogConfig) LogReceiver(alma.acs.logging.engine.LogReceiver)

Aggregations

LogConfig (alma.acs.logging.config.LogConfig)23 AcsLogger (alma.acs.logging.AcsLogger)3 AcsLogLevelDefinition (alma.acs.logging.level.AcsLogLevelDefinition)3 Test (org.junit.Test)3 AcsJIllegalArgumentEx (alma.ACSErrTypeCommon.wrappers.AcsJIllegalArgumentEx)2 IllegalLogLevelsEx (alma.Logging.IllegalLogLevelsEx)2 LogLevels (alma.Logging.LoggingConfigurablePackage.LogLevels)2 UnnamedLogger (alma.maci.loggingconfig.UnnamedLogger)2 Level (java.util.logging.Level)2 LogRecord (java.util.logging.LogRecord)2 Logger (java.util.logging.Logger)2 DaemonThreadFactory (alma.acs.concurrent.DaemonThreadFactory)1 AcsLogLevel (alma.acs.logging.AcsLogLevel)1 LogConfigException (alma.acs.logging.config.LogConfigException)1 LogReceiver (alma.acs.logging.engine.LogReceiver)1 DelayedLogEntry (alma.acs.logging.engine.LogReceiver.DelayedLogEntry)1 AcsXMLLogFormatter (alma.acs.logging.formatters.AcsXMLLogFormatter)1 CoreException (com.cosylab.acs.maci.CoreException)1 ManagerImpl (com.cosylab.acs.maci.manager.ManagerImpl)1 CORBATransport (com.cosylab.acs.maci.plug.CORBATransport)1