Search in sources :

Example 96 with LogRecord

use of java.util.logging.LogRecord in project jdk8u_jdk by JetBrains.

the class LoggerSupplierAPIsTest method validate.

private void validate(int index, boolean thrown, String methodName) {
    assertEquals(supplier.getCount(), invokes[index]);
    assertEquals(handler.getCount(), log_count[index]);
    // Verify associated Throwable is right
    if (thrown) {
        for (LogRecord r : handler.getLogs()) {
            assertTrue(r.getThrown() instanceof HelperEx, "Validate Thrown");
            HelperEx e = (HelperEx) r.getThrown();
            assertEquals(r.getLevel(), e.getLevel(), "Validate Thrown Log Level");
        }
    }
    if (methodName != null) {
        for (LogRecord r : handler.getLogs()) {
            assertEquals(r.getSourceClassName(), getClass().getName());
            assertEquals(r.getSourceMethodName(), methodName);
        }
    }
}
Also used : LogRecord(java.util.logging.LogRecord)

Example 97 with LogRecord

use of java.util.logging.LogRecord in project jdk8u_jdk by JetBrains.

the class MemoryHandlerTest method main.

public static void main(String... args) throws IOException {
    // load logging.propertes for the test
    String tstSrc = System.getProperty("test.src", ".");
    File fname = new File(tstSrc, LM_PROP_FNAME);
    String prop = fname.getCanonicalPath();
    System.setProperty(CFG_FILE_PROP, prop);
    LogManager.getLogManager();
    // create a logger
    logger = Logger.getLogger(MemoryHandlerTest.class.getName());
    // don't have parent handlers get log messages
    logger.setUseParentHandlers(false);
    //
    // Test 1,2: create a CustomMemoryHandler which in the config has
    // specified a target of CustomTargetHandler.  (1) Make sure that it
    // is created and (2) that the target handler is loaded.
    //
    CustomMemoryHandler cmh = new CustomMemoryHandler();
    try {
        logger.addHandler(cmh);
    } catch (RuntimeException rte) {
        throw new RuntimeException("Test Failed: did not load java.util.logging.ConsoleHandler as expected", rte);
    }
    // should have loaded our target handler
    if (CustomTargetHandler.numLoaded != 1) {
        throw new RuntimeException("Test failed: did not load CustomTargetHandler as expected");
    }
    //
    // Test 3: try to add a handler with no target.  This should fail with
    // an exception
    CustomMemoryHandlerNoTarget cmhnt = null;
    try {
        cmhnt = new CustomMemoryHandlerNoTarget();
    } catch (RuntimeException re) {
        // expected -- no target specified
        System.out.println("Info: " + re.getMessage() + " as expected.");
    }
    if (cmhnt != null) {
        throw new RuntimeException("Test Failed: erroneously loaded CustomMemoryHandlerNoTarget");
    }
    // Test 4: log a message and check that the target handler is actually used
    logger.log(Level.WARNING, "Unused");
    if (CustomTargetHandler.numPublished != 1) {
        throw new RuntimeException("Test failed: CustomTargetHandler was not used");
    }
    // Test 5: make sure that SimpleTargetHandler hasn't been erroneously called
    if (SimpleTargetHandler.numPublished != 0) {
        throw new RuntimeException("Test failed: SimpleTargetHandler has been used");
    }
    // Test 6: try using SimpleTargetHanlder via standard MemoryHandler
    // (which has target set to SimpleTargetHandler)
    MemoryHandler mh = new MemoryHandler();
    mh.publish(new LogRecord(Level.INFO, "Unused msg to MemoryHandler"));
    // see if it made it to the SimpleTargetHandler
    if (SimpleTargetHandler.numPublished != 1) {
        throw new RuntimeException("Test failed: SimpleTargetHandler was not used");
    }
}
Also used : LogRecord(java.util.logging.LogRecord) MemoryHandler(java.util.logging.MemoryHandler) File(java.io.File)

Example 98 with LogRecord

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

the class PCGenStatusBar method setSourceLoadErrors.

public void setSourceLoadErrors(List<LogRecord> errors) {
    if (errors != null && !errors.isEmpty()) {
        int nerrors = 0;
        int nwarnings = 0;
        for (LogRecord logRecord : errors) {
            if (logRecord.getLevel().intValue() > Logging.WARNING.intValue()) {
                nerrors++;
            } else if (logRecord.getLevel().intValue() > Logging.INFO.intValue()) {
                nwarnings++;
            }
        }
        if (nerrors > 0) {
            loadStatusLabel.setIcon(Icons.Stop16.getImageIcon());
        } else if (nwarnings > 0) {
            loadStatusLabel.setIcon(Icons.Alert16.getImageIcon());
        } else {
            loadStatusLabel.setIcon(Icons.Ok16.getImageIcon());
        }
        loadStatusLabel.setToolTipText(nerrors + " errors and " + nwarnings + " warnings occurred while loading the sources");
    }
}
Also used : LogRecord(java.util.logging.LogRecord)

Example 99 with LogRecord

use of java.util.logging.LogRecord in project OpenAM by OpenRock.

the class FedletLogger method access.

/**
     * Writes access to a component into a log.
     * @param level indicating log level
     * @param messageId Message id
     * @param data string array of dynamic data only known during run time
     * @param session Session object (it could be null)
     * @param props representing log record columns
     * @exception LogException if there is an error.
     */
public void access(Level level, String messageId, String[] data, Object session, Map props) throws LogException {
    if (isAccessLoggable(level)) {
        LogRecord lr = new LogRecord(level, formatMessage(messageId, data, session));
        accessLogger.log(lr);
    }
}
Also used : LogRecord(java.util.logging.LogRecord)

Example 100 with LogRecord

use of java.util.logging.LogRecord in project voltdb by VoltDB.

the class JdkLogger method log.

/**
     * Log the message at the specified level with the specified throwable if any.
     * This method creates a LogRecord and fills in caller date before calling
     * this instance's JDK14 logger.
     *
     * See bug report #13 for more details.
     */
private void log(String callerFQCN, Level level, String msg, Throwable t) {
    // millis and thread are filled by the constructor
    LogRecord record = new LogRecord(level, msg);
    record.setLoggerName(name());
    record.setThrown(t);
    fillCallerData(callerFQCN, record);
    logger.log(record);
}
Also used : LogRecord(java.util.logging.LogRecord)

Aggregations

LogRecord (java.util.logging.LogRecord)289 Test (org.junit.Test)53 Logger (java.util.logging.Logger)45 ByteArrayOutputStream (java.io.ByteArrayOutputStream)16 Handler (java.util.logging.Handler)16 StreamHandler (java.util.logging.StreamHandler)14 ConsoleHandler (java.util.logging.ConsoleHandler)13 File (java.io.File)12 Properties (java.util.Properties)11 SimpleFormatter (java.util.logging.SimpleFormatter)10 LogRecordCollectingLogger (alma.acs.testsupport.LogRecordCollectingLogger)9 Formatter (java.util.logging.Formatter)9 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 Subscribe (com.google.common.eventbus.Subscribe)6 HashMap (java.util.HashMap)6 Level (java.util.logging.Level)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 FileHandler (java.util.logging.FileHandler)5 Filter (java.util.logging.Filter)4