Search in sources :

Example 6 with LogConfig

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

the class RemoteLoggingTest method testConcurrentRemoteInitAndStop.

/**
	 * Tests the situation in which the ClientLogManager is shut down before it has finished the 
	 * asynchronous <code>initRemoteLogging</code> call.
	 * This can happen in a <code>ComponentClient</code>-based application that performs a short task.
	 * <p>
	 * It is important to make the stdout printing part of this test,
	 * e.g. by using TAT without output suppression tricks,
	 * because among other things we expect the string
	 * <code>Will abort ClientLogManager#initRemoteLogging because remote logging seems no longer needed.</code>
	 * when initRemoteLogging is interrupted by a shutdown.
	 * <p>
	 * The main test thread that logs some messages and the thread that calls initRemoteLogging 
	 * compete for the internal lock {@link ClientLogManager#logQueueLock}, whose functioning is being tested here.
	 * <p>
	 * <b>Unfortunately this cannot be totally deterministic, so we must accept occasional failures
	 * of the kind that the output contains "Remote log: <Info .../>" instead of "Will abort ..." strings, or vice versa.</b>
	 */
public void testConcurrentRemoteInitAndStop() throws InterruptedException {
    DaemonThreadFactory dtf = new DaemonThreadFactory(getName());
    // we try this out for different simulated network delays and shutdown delays
    // @TODO chose values that give deterministic results on most test machines.
    int[] networkDelays = { 0, 2, 16, 21, 100 };
    // @TODO chose values that give deterministic results on most test machines.
    int[] shutdownDelays = { 1, 20, 106 };
    for (int networkDelay : networkDelays) {
        // with the additional arrangement that initRemoteLogging was running when the last log was produced.
        for (int shutdownDelay : shutdownDelays) {
            System.out.println("\n*** Network delay = " + networkDelay + " and shutdown delay = " + shutdownDelay + " ***");
            CountDownLatch syncOnPrepareRemoteLogging = new CountDownLatch(1);
            final ClientLogManagerStandalone clm = new ClientLogManagerStandalone(syncOnPrepareRemoteLogging);
            LogConfig logConfig = clm.getLogConfig();
            logConfig.setDefaultMinLogLevel(AcsLogLevelDefinition.TRACE);
            logConfig.setDefaultMinLogLevelLocal(AcsLogLevelDefinition.TRACE);
            Logger logger = clm.getLoggerForApplication(getName(), true);
            // log something before we init the remote logging:
            logger.info("A healthy info log before initRemoteLogging (" + networkDelay + "/" + shutdownDelay + ")");
            // to keep these two logs in order, which makes manual ref file comparison easier. 
            Thread.sleep(2);
            logger.fine("now that was a fine log before initRemoteLogging (" + networkDelay + "/" + shutdownDelay + ")");
            // simulated network delay for initRemoteLogging-getLogService and write_records
            clm.setDelayMillis(networkDelay);
            // call initRemoteLogging from a separate thread
            Thread initRemoteLoggingThread = dtf.newThread(new Runnable() {

                public void run() {
                    initRemoteLogging(clm);
                }
            });
            initRemoteLoggingThread.start();
            // wait until this thread is actually running, which we check via notification from the ClientLogManager#prepareRemoteLogging method
            // timeout should never apply, just used to stop the test if it gets messed up. 
            assertTrue("initRemoteLogging should have called prepareRemoteLogging by now...", syncOnPrepareRemoteLogging.await(10, TimeUnit.SECONDS));
            logger.info("Another info log after initRemoteLogging (" + networkDelay + "/" + shutdownDelay + ")");
            // depending on the values of networkDelay and shutdownDelay, we may be calling shutdown while 
            // our ClientLogManager is still delivering the log messages.
            Thread.sleep(shutdownDelay);
            clm.shutdown(true);
            // wait for the thread that called initRemoteLogging
            initRemoteLoggingThread.join(10000);
            // wait a bit more for the mock log dispatcher to print out its xml log record
            Thread.sleep(1500);
        }
    }
}
Also used : DaemonThreadFactory(alma.acs.concurrent.DaemonThreadFactory) CountDownLatch(java.util.concurrent.CountDownLatch) Logger(java.util.logging.Logger) LogConfig(alma.acs.logging.config.LogConfig)

Example 7 with LogConfig

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

the class ClientLogManagerTest method testSuppressCorbaRemoteLogging.

/**
	 */
public void testSuppressCorbaRemoteLogging() {
    LogConfig config = clientLogManager.getLogConfig();
    // the internal logger of ClientLogManager "alma.acs.logging"
    assertEquals(1, config.getLoggerNames().size());
    AcsLogger orbLog1 = clientLogManager.getLoggerForCorba("jacorb_1", true);
    assertEquals(2, config.getLoggerNames().size());
    AcsLogger orbLog1b = clientLogManager.getLoggerForCorba("jacorb_1", true);
    assertSame(orbLog1, orbLog1b);
    assertEquals(2, config.getLoggerNames().size());
    AcsLogger orbLog2 = clientLogManager.getLoggerForCorba("jacorb_2", true);
    assertNotSame(orbLog1, orbLog2);
    assertEquals(3, config.getLoggerNames().size());
    // From the container logger, the process name will be derived, and the corba loggers will get it appended
    AcsLogger contLog = clientLogManager.getLoggerForContainer("myContainer");
    Set<String> loggerNames = config.getLoggerNames();
    assertEquals(4, loggerNames.size());
    assertTrue(loggerNames.contains("alma.acs.logging"));
    assertTrue(loggerNames.contains("jacorb_1@myContainer"));
    assertTrue(loggerNames.contains("jacorb_2@myContainer"));
    assertTrue(loggerNames.contains("myContainer"));
    config.setDefaultMinLogLevelLocal(AcsLogLevelDefinition.INFO);
    config.setDefaultMinLogLevel(AcsLogLevelDefinition.DEBUG);
    // the log level must be the smaller one of stdout and remote level
    assertEquals(Level.FINE, orbLog1.getLevel());
    assertEquals(Level.FINE, orbLog2.getLevel());
    assertEquals(Level.FINE, contLog.getLevel());
    clientLogManager.suppressCorbaRemoteLogging();
    // now for corba loggers the remote handler's level must be infinite, and the local level should determine the logger level. 
    // todo: check levels directly on the handlers
    assertEquals(AcsLogLevel.INFO, orbLog1.getLevel());
    assertEquals(AcsLogLevel.INFO, orbLog2.getLevel());
    assertEquals(AcsLogLevel.FINE, contLog.getLevel());
    assertEquals(4, loggerNames.size());
}
Also used : LogConfig(alma.acs.logging.config.LogConfig)

Example 8 with LogConfig

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

the class EngineFilteringTest method setUp.

/**
	 * Setup the environment by creating the engine with a null set of filters.
	 * The engine is disconnected because some of the tests do not need the
	 * connection alive.
	 * 
	 * @see alma.acs.component.client.ComponentClientTestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    receivedLogs = new Vector<ILogEntry>();
    assertNotNull(receivedLogs);
    receivedLogs.clear();
    xmlLogsCount = new AtomicInteger(0);
    xmlInfos = 0;
    assertNotNull(m_logger);
    AcsLogger acsLogger = m_logger;
    LogConfig config = new LogConfig();
    acsLogger.configureLogging(config);
    engine = new LCEngine();
    assertNotNull(engine);
    engine.addLogErrorListener(this);
    engine.addLogConnectionListener(this);
    engine.addLogListener(this);
    engine.addRawLogListener(this);
}
Also used : ILogEntry(com.cosylab.logging.engine.log.ILogEntry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LCEngine(com.cosylab.logging.engine.ACS.LCEngine) AcsLogger(alma.acs.logging.AcsLogger) LogConfig(alma.acs.logging.config.LogConfig)

Example 9 with LogConfig

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

the class EventSubscriberSmEngineTest method configureLogging.

private void configureLogging(AcsLogLevelDefinition localLevel) {
    String scxmlLoggerName = "scxml@" + testMethodName;
    LogConfig logConfig = ClientLogManager.getAcsLogManager().getLogConfig();
    logConfig.setMinLogLevelLocal(localLevel, scxmlLoggerName);
    logConfig.setMinLogLevel(AcsLogLevelDefinition.OFF, scxmlLoggerName);
    ClientLogManager.getAcsLogManager().suppressRemoteLogging();
}
Also used : LogConfig(alma.acs.logging.config.LogConfig)

Example 10 with LogConfig

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

the class AcsLoggerHelper method setHibernateLogLevels.

public void setHibernateLogLevels(AcsLogLevelDefinition localLevel, AcsLogLevelDefinition remoteLevel) {
    LogConfig logConfig = ClientLogManager.getAcsLogManager().getLogConfig();
    String name = HibernateLoggerHelper.HIBERNATE_LOGGER_NAME_PREFIX + '@' + loggerName;
    logConfig.setMinLogLevelLocal(localLevel, name);
    logConfig.setMinLogLevel(remoteLevel, name);
}
Also used : LogConfig(alma.acs.logging.config.LogConfig)

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