Search in sources :

Example 61 with Logger

use of java.util.logging.Logger in project robovm by robovm.

the class Jdk14Logger method log.

// --------------------------------------------------------- Public Methods
private void log(Level level, String msg, Throwable ex) {
    Logger logger = getLogger();
    if (logger.isLoggable(level)) {
        // Hack (?) to get the stack trace.
        Throwable dummyException = new Throwable();
        StackTraceElement[] locations = dummyException.getStackTrace();
        // Caller will be the third element
        String cname = "unknown";
        String method = "unknown";
        if (locations != null && locations.length > 2) {
            StackTraceElement caller = locations[2];
            cname = caller.getClassName();
            method = caller.getMethodName();
        }
        if (ex == null) {
            logger.logp(level, cname, method, msg);
        } else {
            logger.logp(level, cname, method, msg, ex);
        }
    }
}
Also used : Logger(java.util.logging.Logger)

Example 62 with Logger

use of java.util.logging.Logger in project robovm by robovm.

the class OldLogManagerTest method testGetLogger_nameSpace.

/*
     * test for method public Logger getLogger(String name)
     */
public void testGetLogger_nameSpace() throws Exception {
    // test name with space
    Logger foo = new MockLogger(FOO, null);
    Logger fooBeforeSpace = new MockLogger(FOO + " ", null);
    Logger fooAfterSpace = new MockLogger(" " + FOO, null);
    Logger fooWithBothSpace = new MockLogger(" " + FOO + " ", null);
    assertTrue(mockManager.addLogger(foo));
    assertTrue(mockManager.addLogger(fooBeforeSpace));
    assertTrue(mockManager.addLogger(fooAfterSpace));
    assertTrue(mockManager.addLogger(fooWithBothSpace));
    assertSame(foo, mockManager.getLogger(FOO));
    assertSame(fooBeforeSpace, mockManager.getLogger(FOO + " "));
    assertSame(fooAfterSpace, mockManager.getLogger(" " + FOO));
    assertSame(fooWithBothSpace, mockManager.getLogger(" " + FOO + " "));
}
Also used : Logger(java.util.logging.Logger)

Example 63 with Logger

use of java.util.logging.Logger in project robovm by robovm.

the class OldLogManagerTest method testGetLogger_duplicateName.

/*
     * test for method public Logger getLogger(String name)
     */
public void testGetLogger_duplicateName() throws Exception {
    // test duplicate name
    // add logger with duplicate name has no effect
    mockManager.reset();
    Logger foo2 = new MockLogger(FOO, null);
    Logger foo3 = new MockLogger(FOO, null);
    mockManager.addLogger(foo2);
    assertSame(foo2, mockManager.getLogger(FOO));
    mockManager.addLogger(foo3);
    assertSame(foo2, mockManager.getLogger(FOO));
    Enumeration<String> enumar2 = mockManager.getLoggerNames();
    int i = 0;
    while (enumar2.hasMoreElements()) {
        enumar2.nextElement();
        i++;
    }
    assertEquals(1, i);
}
Also used : Logger(java.util.logging.Logger)

Example 64 with Logger

use of java.util.logging.Logger in project robovm by robovm.

the class OldLogManagerTest method testGetLogger_hierarchy.

/*
     * test for method public Logger getLogger(String name)
     */
public void testGetLogger_hierarchy() throws Exception {
    // test hierarchy
    Logger foo = new MockLogger("testGetLogger_hierachy.foo", null);
    // but for non-mock LogManager, foo's parent should be root
    assertTrue(manager.addLogger(foo));
    assertSame(manager.getLogger(""), manager.getLogger("testGetLogger_hierachy.foo").getParent());
}
Also used : Logger(java.util.logging.Logger)

Example 65 with Logger

use of java.util.logging.Logger in project GCViewer by chewiebug.

the class AbstractGCModelLoaderImpl method doInBackground.

@Override
protected GCModel doInBackground() throws Exception {
    setProgress(0);
    final GCModel result;
    try {
        result = loadGcModel();
    } catch (DataReaderException | RuntimeException e) {
        Logger logger = getGcResource().getLogger();
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, "Failed to load GCModel from " + getGcResource().getResourceName(), e);
        }
        throw e;
    }
    return result;
}
Also used : DataReaderException(com.tagtraum.perf.gcviewer.imp.DataReaderException) Logger(java.util.logging.Logger) GCModel(com.tagtraum.perf.gcviewer.model.GCModel)

Aggregations

Logger (java.util.logging.Logger)499 Test (org.junit.Test)70 LogRecord (java.util.logging.LogRecord)60 ActionReport (org.glassfish.api.ActionReport)56 Handler (java.util.logging.Handler)52 IOException (java.io.IOException)37 File (java.io.File)36 Level (java.util.logging.Level)25 ArrayList (java.util.ArrayList)22 ConsoleHandler (java.util.logging.ConsoleHandler)19 Properties (java.util.Properties)15 SimpleFormatter (java.util.logging.SimpleFormatter)15 Config (com.sun.enterprise.config.serverbeans.Config)14 HashMap (java.util.HashMap)14 Map (java.util.Map)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ResourceBundle (java.util.ResourceBundle)11 LogManager (java.util.logging.LogManager)11 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)11 BlockingQueueHandler (fish.payara.nucleus.notification.BlockingQueueHandler)10