Search in sources :

Example 21 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)

Example 22 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 23 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 24 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 25 with Handler

use of java.util.logging.Handler in project adempiere by adempiere.

the class SilentSetup method main.

/**
	 * 	Start
	 * 	@param args Log Level e.g. ALL, FINE
	 */
public static void main(String[] args) {
    CLogMgt.initialize(true);
    Handler fileHandler = new CLogFile(System.getProperty("user.dir"), false, false);
    CLogMgt.addHandler(fileHandler);
    //	Log Level
    if (args.length > 0)
        CLogMgt.setLevel(args[0]);
    else
        CLogMgt.setLevel(Level.INFO);
    //	File Logger at least FINE
    if (fileHandler.getLevel().intValue() > Level.FINE.intValue())
        fileHandler.setLevel(Level.FINE);
    new SilentSetup();
}
Also used : CLogFile(org.compiere.util.CLogFile) Handler(java.util.logging.Handler)

Aggregations

Handler (java.util.logging.Handler)108 Logger (java.util.logging.Logger)35 ConsoleHandler (java.util.logging.ConsoleHandler)22 LogRecord (java.util.logging.LogRecord)16 Test (org.junit.Test)15 FileHandler (java.util.logging.FileHandler)13 IOException (java.io.IOException)9 File (java.io.File)8 Level (java.util.logging.Level)7 SimpleFormatter (java.util.logging.SimpleFormatter)7 Formatter (java.util.logging.Formatter)6 LogManager (java.util.logging.LogManager)6 PrintStream (java.io.PrintStream)5 ArrayList (java.util.ArrayList)4 SLF4JBridgeHandler (org.slf4j.bridge.SLF4JBridgeHandler)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 StringTokenizer (java.util.StringTokenizer)3 StdOutConsoleHandler (alma.acs.logging.StdOutConsoleHandler)2 ConsoleLogFormatter (alma.acs.logging.formatters.ConsoleLogFormatter)2 MonitoredResource (com.google.cloud.MonitoredResource)2