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);
}
}
}
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 + " "));
}
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);
}
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());
}
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;
}
Aggregations