use of alma.acs.logging.level.AcsLogLevelDefinition 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.level.AcsLogLevelDefinition 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.level.AcsLogLevelDefinition in project ACS by ACS-Community.
the class LogConfigTest method testDefaultValues.
/**
* Tests the config values returned from {@link LogConfig}
* with at most env vars for default levels being set (can be enforced by TAT!),
* but without CDB or other information being considered.
* <p>
* Also asserts that none of these calls return the original object,
* but instead a copy of it. This indirectly exercises the equals method.
*/
public void testDefaultValues() throws Exception {
logger.info("============ Running testDefaultValues ============");
assertEquals("Log", logConfig.getCentralizedLogger());
assertEquals(100, logConfig.getDispatchPacketSize());
LoggingConfig schemaDefaults = new LoggingConfig();
// We verify that the castor-generated class actually has the current schema defaults.
// These values must be adjusted when the schema is changed.
// In that case also the values in the simulated CDB's xml might have to be changed
// in order to still be different from the default values.
// 0 named loggers
assertEquals(0, schemaDefaults.getCount());
assertEquals(100, schemaDefaults.getDispatchPacketSize());
assertEquals(10, schemaDefaults.getFlushPeriodSeconds());
assertEquals(LogLevel.VALUE_10, schemaDefaults.getImmediateDispatchLevel());
assertEquals(1000, schemaDefaults.getMaxLogQueueSize());
assertEquals(LogLevel.VALUE_2, schemaDefaults.getMinLogLevelLocal());
assertEquals(LogLevel.VALUE_2, schemaDefaults.getMinLogLevel());
assertEquals("Log", schemaDefaults.getCentralizedLogger());
AcsLogLevelDefinition defaultMinLogLevelLocal = AcsLogLevelDefinition.fromXsdLogLevel(schemaDefaults.getMinLogLevelLocal());
// but if env vars are set, we may have different default levels
Integer PROP_ACS_LOG_STDOUT = Integer.getInteger(LogConfig.PROPERTYNAME_MIN_LOG_LEVEL_LOCAL);
if (PROP_ACS_LOG_STDOUT != null) {
defaultMinLogLevelLocal = AcsLogLevelDefinition.fromInteger(PROP_ACS_LOG_STDOUT.intValue());
logger.info("Using default stdout level from env var: " + defaultMinLogLevelLocal);
} else {
logger.info("No env var setting found for " + LogConfig.PROPERTYNAME_MIN_LOG_LEVEL_LOCAL);
}
AcsLogLevelDefinition defaultMinLogLevel = AcsLogLevelDefinition.fromXsdLogLevel(schemaDefaults.getMinLogLevel());
Integer PROP_ACS_LOG_REMOTE = Integer.getInteger(LogConfig.PROPERTYNAME_MIN_LOG_LEVEL);
if (PROP_ACS_LOG_REMOTE != null) {
defaultMinLogLevel = AcsLogLevelDefinition.fromInteger(PROP_ACS_LOG_REMOTE.intValue());
logger.info("Using default remote level from env var: " + defaultMinLogLevelLocal);
} else {
logger.info("No env var setting found for " + LogConfig.PROPERTYNAME_MIN_LOG_LEVEL);
}
// our logConfig should give the correct default values, coming from schema or env var
assertEquals(defaultMinLogLevelLocal, logConfig.getDefaultMinLogLevelLocal());
assertEquals(defaultMinLogLevel, logConfig.getDefaultMinLogLevel());
// Check default data other than log levels
assertEquals(schemaDefaults.getCentralizedLogger(), logConfig.getCentralizedLogger());
assertEquals(schemaDefaults.getImmediateDispatchLevel(), logConfig.getImmediateDispatchLevel().toXsdLevel());
assertEquals(schemaDefaults.getDispatchPacketSize(), logConfig.getDispatchPacketSize());
assertEquals(schemaDefaults.getFlushPeriodSeconds(), logConfig.getFlushPeriodSeconds());
// Get log levels for not existing named loggers, which should result in the default log levels being used
UnnamedLogger namedLogConfig1 = logConfig.getNamedLoggerConfig(null);
assertEquals(defaultMinLogLevel, AcsLogLevelDefinition.fromXsdLogLevel(namedLogConfig1.getMinLogLevel()));
assertEquals(defaultMinLogLevelLocal, AcsLogLevelDefinition.fromXsdLogLevel(namedLogConfig1.getMinLogLevelLocal()));
UnnamedLogger namedLogConfig2 = logConfig.getNamedLoggerConfig("nonExistingLogger");
assertNotSame(namedLogConfig1, namedLogConfig2);
assertEquals(defaultMinLogLevel, AcsLogLevelDefinition.fromXsdLogLevel(namedLogConfig2.getMinLogLevel()));
assertEquals(defaultMinLogLevelLocal, AcsLogLevelDefinition.fromXsdLogLevel(namedLogConfig2.getMinLogLevelLocal()));
}
use of alma.acs.logging.level.AcsLogLevelDefinition in project ACS by ACS-Community.
the class LogConfigTest method testCDBValues.
/**
* Tests logging config from the CDB, for both cases
* (a) that env vars beat CDB settings e.g. for normal CDB reading,
* (b) that CDB beats env vars e.g. during a refresh from CDB triggered via LoggingConfigurable API.
*/
public void testCDBValues() throws Exception {
logger.info("============ Running testCDBValues ============");
// we simulate an ACS_LOG_STDOUT env var setting
String ACS_LOG_STDOUT_ORIGINAL = System.getProperty(LogConfig.PROPERTYNAME_MIN_LOG_LEVEL_LOCAL);
String ACS_LOG_REMOTE_ORIGINAL = System.getProperty(LogConfig.PROPERTYNAME_MIN_LOG_LEVEL);
String ACS_LOG_STDOUT = "" + AcsLogLevelDefinition.EMERGENCY.value;
assertFalse("Fix this test to chose a different env var than the default", ACS_LOG_STDOUT.equals(ACS_LOG_STDOUT_ORIGINAL));
System.setProperty(LogConfig.PROPERTYNAME_MIN_LOG_LEVEL_LOCAL, ACS_LOG_STDOUT);
logger.info("Set property (env var) for local default level to " + ACS_LOG_STDOUT);
// and remove any possibly present property from env var ACS_LOG_CENTRAL
System.clearProperty(LogConfig.PROPERTYNAME_MIN_LOG_LEVEL);
logger.info("Removed property (env var) for remote default level");
// the schema defaults as reference
LoggingConfig schemaDefaults = new LoggingConfig();
AcsLogLevelDefinition defaultMinLogLevel = AcsLogLevelDefinition.fromXsdLogLevel(schemaDefaults.getMinLogLevel());
AcsLogLevelDefinition defaultMinLogLevelLocal = AcsLogLevelDefinition.fromXsdLogLevel(schemaDefaults.getMinLogLevelLocal());
// before we read the CDB, let's verify that the env var and default log levels are correct
logConfig.initialize(false);
assertEquals(defaultMinLogLevel, logConfig.getDefaultMinLogLevel());
assertEquals(AcsLogLevelDefinition.EMERGENCY, logConfig.getDefaultMinLogLevelLocal());
// the simulated test CDB to configure our loggers from
String cdbContainerPath = "MACI/Containers/frodoContainer";
String frodoContainerXml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> " + "<Container xmlns=\"urn:schemas-cosylab-com:Container:1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:log=\"urn:schemas-cosylab-com:LoggingConfig:1.0\">" + "<LoggingConfig " + " minLogLevel=\"4\" " + " minLogLevelLocal=\"3\" " + " centralizedLogger=\"LogForFrodo\" " + " maxLogQueueSize=\"200\" " + " immediateDispatchLevel=\"8\" " + " dispatchPacketSize=\"33\" " + " >" + "<log:_ Name=\"MyMuteComponent\" minLogLevel=\"5\" minLogLevelLocal=\"6\" />" + "</LoggingConfig>" + "</Container>";
TestCDB testCDB = new TestCDB();
testCDB.addCurlToXmlMapping(cdbContainerPath, frodoContainerXml);
logConfig.setCDBLoggingConfigPath(cdbContainerPath);
logConfig.setCDB(testCDB);
// first the normal case where the env var default level beats the CDB default level
logConfig.initialize(false);
assertEquals("CDB must beat schema default", AcsLogLevelDefinition.INFO, logConfig.getDefaultMinLogLevel());
assertEquals("Env var must beat CDB", AcsLogLevelDefinition.EMERGENCY, logConfig.getDefaultMinLogLevelLocal());
assertEquals("LogForFrodo", logConfig.getCentralizedLogger());
assertSame(AcsLogLevelDefinition.ERROR, logConfig.getImmediateDispatchLevel());
assertEquals(33, logConfig.getDispatchPacketSize());
assertEquals(200, logConfig.getMaxLogQueueSize());
Set<String> loggerNames = logConfig.getLoggerNames();
assertEquals(1, loggerNames.size());
assertTrue(loggerNames.contains("MyMuteComponent"));
// was not in CDB, thus default should be used
assertEquals(schemaDefaults.getFlushPeriodSeconds(), logConfig.getFlushPeriodSeconds());
// next the special case of CDB refresh via dynamic API, where the CDB beats the env var default levels
logConfig.initialize(true);
assertSame("CDB must beat schema default", AcsLogLevelDefinition.INFO, logConfig.getDefaultMinLogLevel());
assertSame("CDB must beat env var", AcsLogLevelDefinition.DEBUG, logConfig.getDefaultMinLogLevelLocal());
assertEquals("LogForFrodo", logConfig.getCentralizedLogger());
assertSame(AcsLogLevelDefinition.ERROR, logConfig.getImmediateDispatchLevel());
assertEquals(33, logConfig.getDispatchPacketSize());
assertEquals(200, logConfig.getMaxLogQueueSize());
loggerNames = logConfig.getLoggerNames();
assertEquals(1, loggerNames.size());
assertTrue(loggerNames.contains("MyMuteComponent"));
// was not in CDB, thus default should be used
assertEquals(schemaDefaults.getFlushPeriodSeconds(), logConfig.getFlushPeriodSeconds());
UnnamedLogger myMuteloggerConfig = logConfig.getNamedLoggerConfig("MyMuteComponent");
assertEquals(LogLevel.VALUE_5, myMuteloggerConfig.getMinLogLevel());
assertEquals(LogLevel.VALUE_6, myMuteloggerConfig.getMinLogLevelLocal());
// Test logger configuration given in the CDB separately for a component in the Components.xml file, not with the rest of LoggingConfig in the Container xml.
String separateConfigComponent1 = "testComp1";
String separateConfigComponent2 = "testComp2";
String componentsXml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> " + "<Components xmlns=\"urn:schemas-cosylab-com:Components:1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"> " + createComponentsCdbXml(separateConfigComponent1, "IDL_TYPE_1", "some.class1", "zampaione", true, 2, 8) + createComponentsCdbXml(separateConfigComponent2, "IDL_TYPE_2", "some.class2", "zampaione", true, 5, 6) + "</Components>";
logger.info("componentsXml = " + componentsXml);
String cdbComponentsPath = "MACI/Components";
testCDB.addCurlToXmlMapping(cdbComponentsPath, componentsXml);
logConfig.setCDBComponentPath(separateConfigComponent1, cdbComponentsPath);
logConfig.setCDBComponentPath(separateConfigComponent2, cdbComponentsPath);
logConfig.initialize(false);
loggerNames = logConfig.getLoggerNames();
// assertEquals(2, loggerNames.size());
assertTrue(loggerNames.contains("MyMuteComponent"));
// assertTrue(loggerNames.contains(separateConfigComponent1));
// assertTrue(loggerNames.contains(separateConfigComponent2));
UnnamedLogger separateConfig1 = logConfig.getNamedLoggerConfig(separateConfigComponent1);
assertEquals(LogLevel.VALUE_2, separateConfig1.getMinLogLevel());
assertEquals(LogLevel.VALUE_8, separateConfig1.getMinLogLevelLocal());
UnnamedLogger separateConfig2 = logConfig.getNamedLoggerConfig(separateConfigComponent2);
assertEquals(LogLevel.VALUE_5, separateConfig2.getMinLogLevel());
assertEquals(LogLevel.VALUE_6, separateConfig2.getMinLogLevelLocal());
// restore env vars (probably not necessary)
if (ACS_LOG_STDOUT_ORIGINAL != null) {
System.setProperty(LogConfig.PROPERTYNAME_MIN_LOG_LEVEL_LOCAL, ACS_LOG_STDOUT_ORIGINAL);
}
if (ACS_LOG_REMOTE_ORIGINAL != null) {
System.setProperty(LogConfig.PROPERTYNAME_MIN_LOG_LEVEL, ACS_LOG_REMOTE_ORIGINAL);
}
}
use of alma.acs.logging.level.AcsLogLevelDefinition in project ACS by ACS-Community.
the class TestLogLevelsCompTest method testLoggingConfigurableCentralLogLevels.
/**
* This test uses the LoggingConfigurable interface implemented by all containers to set log levels
* These log levels are then expected to be independent of the initial CDB settings, according to precedence rules.
* The test verifies that the levels are applied correctly by commanding the test components to log messages
* at various log levels. The test listens on the Log service to compare the messages actually sent
* with what is expected for the current log level settings.
*/
public void testLoggingConfigurableCentralLogLevels() throws Exception {
LogSeriesExpectant expectant = new LogSeriesExpectant(getLogReceiver());
// All log levels, including OFF
int[] centralLogLevels;
// Excluding OFF
int[] sendLogLevels;
// Only with OFF
int[] offLogLevels;
centralLogLevels = new int[AcsLogLevelDefinition.values().length];
sendLogLevels = new int[AcsLogLevelDefinition.values().length - 1];
offLogLevels = new int[1];
int i = 0;
int maxLogLevel = -1;
// log levels ordered, with OFF being the last one.
for (AcsLogLevelDefinition lld : AcsLogLevelDefinition.values()) {
if (lld.name.equalsIgnoreCase("OFF")) {
offLogLevels[0] = lld.value;
} else {
maxLogLevel = Math.max(maxLogLevel, lld.value);
sendLogLevels[i] = lld.value;
}
centralLogLevels[i++] = lld.value;
}
int waitTimeSeconds = 4;
for (TestLogLevelsComp testComp : components) {
String componentName = testComp.name();
// Prepare the log levels via the container's LoggingConfigurable interface
String containerName = containerTestUtil.resolveContainerName(componentName);
LoggingConfigurable containerLogConfig = containerTestUtil.getContainerLoggingIF(containerName);
// @TODO get logger name from the component via a new IDL method, because the logger name
// may not be the same as the component name (e.g. for C++ components).
String loggerName = componentName;
// Set the log level that our test component is subject to (either default level or individual level depending on CDB config)
alma.Logging.LoggingConfigurablePackage.LogLevels componentLogLevels = containerLogConfig.get_logLevels(loggerName);
for (int level : centralLogLevels) {
// The min log level we set for the component and test its log output against.
short minLogLevelCentral = (short) level;
componentLogLevels.minLogLevel = minLogLevelCentral;
if (componentLogLevels.useDefault) {
// @TODO: add a test as well to change the specific level, and then verify
// if useDefault becomes false.
containerLogConfig.set_default_logLevels(componentLogLevels);
m_logger.info("Set default log level for container " + containerName + " to " + minLogLevelCentral + " to be used by component " + componentName);
} else {
// @TODO: add a test to change the default level, and see if it impacts specific logger
containerLogConfig.set_logLevels(loggerName, componentLogLevels);
m_logger.info("Set individual log level for component " + componentName + " (running in container " + containerName + ") to " + minLogLevelCentral);
}
expectant.clearLogs();
m_logger.info("Will call 'logDummyMessages' on component " + componentName);
testComp.logDummyMessages(sendLogLevels);
//testComp.logDummyMessages(centralLogLevels);
m_logger.info("Will wait " + waitTimeSeconds + " seconds to receive (some of) these log messages.");
LogSeriesExpectant.LogList logRecordsReceived = expectant.awaitLogRecords(loggerName, waitTimeSeconds);
System.out.println("Got " + logRecordsReceived.size() + " records from logger " + loggerName);
for (LogReceiver.ReceivedLogRecord logRecord : logRecordsReceived) {
System.out.println("(level=" + logRecord.getLevel().acsCoreLevel.value + ") " + logRecord.getMessage());
}
if (minLogLevelCentral > maxLogLevel) {
// minLogLevelCentral must be set to OFF - no logs should get through
assertEquals(0, logRecordsReceived.size());
} else {
// The next assertion will fail here if there were no logs received,
// as getMinLogLevel will return then the value 2147483647 (-1).
assertEquals(minLogLevelCentral, logRecordsReceived.getMinLogLevel());
assertEquals(maxLogLevel, logRecordsReceived.getMaxLogLevel());
}
// logging a msg at level OFF should lead to an exception, independent from central level
try {
testComp.logDummyMessages(offLogLevels);
// C++ containers don't seem to be able to throw exception in this case
m_logger.info("Sending a log with level OFF did not throw exception.");
// Consume the log that says it is the last log message, unless the current level is OFF
if (minLogLevelCentral <= maxLogLevel) {
logRecordsReceived = expectant.awaitLogRecords(loggerName, waitTimeSeconds);
assertEquals(1, logRecordsReceived.size());
}
} catch (org.omg.CORBA.UNKNOWN ex) {
if (ex.getLocalizedMessage().startsWith("Server-side Exception: java.lang.IllegalArgumentException")) {
// Obviously the case for Java
System.out.println("Got illegal argument exception for attempting to send log with level OFF, as expected.");
} else if (ex.getLocalizedMessage().startsWith("Server-side Exception: null")) {
// This is what Python does
System.out.println("Got exception for attempting to send log with level OFF, as expected.");
} else {
// The exception we got is not the one expected
throw ex;
}
}
//System.out.println("Finished testing level " + level);
}
//System.out.println("Finished testing component " + componentName);
}
//System.out.println("Finished testing all components - done with testLoggingConfigurableCentralLogLevels()");
}
Aggregations