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);
}
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);
}
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());
}
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);
}
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();
}
Aggregations