Search in sources :

Example 16 with Handler

use of java.util.logging.Handler in project pcgen by PCGen.

the class SourceFileLoader method execute.

@Override
public void execute() {
    Globals.emptyLists();
    SettingsHandler.setGame(selectedGame.getName());
    Globals.initPreferences();
    Globals.emptyLists();
    Handler handler = new LoadHandler();
    Logging.registerHandler(handler);
    try {
        loadCampaigns();
    } catch (PersistenceLayerException e) {
        Logging.errorPrint("Failed to load sources", e);
        uiDelegate.showErrorMessage(Constants.APPLICATION_NAME, "Failed to load sources, see log for details.");
    }
    Logging.removeHandler(handler);
}
Also used : PrereqHandler(pcgen.core.prereq.PrereqHandler) SettingsHandler(pcgen.core.SettingsHandler) Handler(java.util.logging.Handler)

Example 17 with Handler

use of java.util.logging.Handler in project ACS by ACS-Community.

the class ClientLogManagerTest method assertLogLevels.

/**
	 * Checks that an AcsLogger has local and remote handlers configured with the correct levels.
	 */
private void assertLogLevels(AcsLogger logger, AcsLogLevelDefinition expectedLocalLevel, AcsLogLevelDefinition expectedRemoteLevel) {
    Handler[] handlers = logger.getHandlers();
    assertTrue(handlers.length == 2);
    StdOutConsoleHandler localHandler = null;
    AcsLoggingHandler remoteHandler = null;
    for (Handler handler : handlers) {
        if (handler instanceof StdOutConsoleHandler) {
            localHandler = (StdOutConsoleHandler) handler;
        } else if (handler instanceof AcsLoggingHandler) {
            remoteHandler = (AcsLoggingHandler) handler;
        } else {
            fail("Unexpected handler type " + handler.getClass().getName() + " encountered.");
        }
    }
    assertNotNull(localHandler);
    assertNotNull(remoteHandler);
    assertEquals(AcsLogLevel.getLowestMatchingJdkLevel(expectedLocalLevel), localHandler.getLevel());
    assertEquals(AcsLogLevel.getLowestMatchingJdkLevel(expectedRemoteLevel), remoteHandler.getLevel());
}
Also used : Handler(java.util.logging.Handler)

Example 18 with Handler

use of java.util.logging.Handler in project ACS by ACS-Community.

the class ClientLogManagerTest method testLoggerStructure.

public void testLoggerStructure() {
    Logger containerLogger = clientLogManager.getLoggerForContainer("test");
    assertNotNull(containerLogger);
    Logger acsRemoteLogger = containerLogger.getParent();
    assertNotNull(acsRemoteLogger);
    assertFalse(acsRemoteLogger.getUseParentHandlers());
    Logger rootLogger = acsRemoteLogger.getParent();
    assertNotNull(rootLogger);
    assertNull(rootLogger.getParent());
    Handler[] handlers = containerLogger.getHandlers();
    assertTrue(handlers.length == 2);
    StdOutConsoleHandler localHandler = null;
    AcsLoggingHandler remoteHandler = null;
    for (Handler handler : handlers) {
        if (handler instanceof StdOutConsoleHandler) {
            localHandler = (StdOutConsoleHandler) handler;
        } else if (handler instanceof AcsLoggingHandler) {
            remoteHandler = (AcsLoggingHandler) handler;
        } else {
            fail("Unexpected handler type " + handler.getClass().getName() + " encountered.");
        }
    }
    assertNotNull(localHandler);
    assertNotNull(remoteHandler);
    Formatter localFormatter = localHandler.getFormatter();
    assertTrue("localFormatter should not be of type " + localFormatter.getClass().getName(), localFormatter instanceof ConsoleLogFormatter);
    Handler[] parentHandlers = acsRemoteLogger.getHandlers();
    assertTrue(parentHandlers.length == 0);
    assertEquals(AcsLogLevel.DELOUSE, remoteHandler.getLevel());
    containerLogger.info("I'm a good pedigree logger.");
}
Also used : ConsoleLogFormatter(alma.acs.logging.formatters.ConsoleLogFormatter) Formatter(java.util.logging.Formatter) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger) ConsoleLogFormatter(alma.acs.logging.formatters.ConsoleLogFormatter)

Example 19 with Handler

use of java.util.logging.Handler 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 20 with Handler

use of java.util.logging.Handler in project ACS by ACS-Community.

the class AcsLoggerTest method testWrapJdkLogger.

public void testWrapJdkLogger() {
    assertSame("Expected reuse of AcsLogger", acsLogger, AcsLogger.fromJdkLogger(acsLogger, null));
    Logger jdkLogger = TestLogger.getLogger("myJdkLogger");
    Handler[] handlers = jdkLogger.getHandlers();
    assertEquals(1, handlers.length);
    // to get an ISO timestamp on stdout, for TAT/sed filtering.
    handlers[0].setFormatter(new ConsoleLogFormatter());
    AcsLogger wrapper = AcsLogger.fromJdkLogger(jdkLogger, null);
    assertEquals("myJdkLoggerwrapper", wrapper.getName());
    wrapper.info("A message logged by the AcsLogger that wraps the jdkLogger");
}
Also used : Handler(java.util.logging.Handler) OperatorLogger(alma.acs.logging.domainspecific.OperatorLogger) ArrayContextLogger(alma.acs.logging.domainspecific.ArrayContextLogger) AntennaContextLogger(alma.acs.logging.domainspecific.AntennaContextLogger) DeveloperLogger(alma.acs.logging.domainspecific.DeveloperLogger) ScienceLogger(alma.acs.logging.domainspecific.ScienceLogger) TestLogger(alma.acs.testsupport.TestLogger) Logger(java.util.logging.Logger) ConsoleLogFormatter(alma.acs.logging.formatters.ConsoleLogFormatter)

Aggregations

Handler (java.util.logging.Handler)135 Logger (java.util.logging.Logger)52 ConsoleHandler (java.util.logging.ConsoleHandler)30 LogRecord (java.util.logging.LogRecord)24 Test (org.junit.Test)22 FileHandler (java.util.logging.FileHandler)17 File (java.io.File)14 IOException (java.io.IOException)13 Level (java.util.logging.Level)11 SimpleFormatter (java.util.logging.SimpleFormatter)8 Formatter (java.util.logging.Formatter)7 LogManager (java.util.logging.LogManager)6 PrintStream (java.io.PrintStream)5 ArrayList (java.util.ArrayList)5 SLF4JBridgeHandler (org.slf4j.bridge.SLF4JBridgeHandler)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 StringTokenizer (java.util.StringTokenizer)3 StdOutConsoleHandler (alma.acs.logging.StdOutConsoleHandler)2