use of java.util.logging.Handler in project google-cloud-java by GoogleCloudPlatform.
the class LoggingHandlerTest method testPublishCustomResource.
@Test
public void testPublishCustomResource() {
expect(options.getProjectId()).andReturn(PROJECT).anyTimes();
expect(options.getService()).andReturn(logging);
logging.setFlushSeverity(Severity.ERROR);
expectLastCall().once();
logging.setWriteSynchronicity(Synchronicity.ASYNC);
expectLastCall().once();
MonitoredResource resource = MonitoredResource.of("custom", ImmutableMap.<String, String>of());
logging.write(ImmutableList.of(FINEST_ENTRY), WriteOption.logName(LOG_NAME), WriteOption.resource(resource), WriteOption.labels(BASE_SEVERITY_MAP));
expectLastCall().once();
replay(options, logging);
Handler handler = new LoggingHandler(LOG_NAME, options, resource);
handler.setLevel(Level.ALL);
handler.setFormatter(new TestFormatter());
handler.publish(newLogRecord(Level.FINEST, MESSAGE));
}
use of java.util.logging.Handler in project google-cloud-java by GoogleCloudPlatform.
the class LoggingHandlerTest method testEnhancedLogEntry.
@Test
public void testEnhancedLogEntry() {
expect(options.getProjectId()).andReturn(PROJECT).anyTimes();
expect(options.getService()).andReturn(logging);
MonitoredResource resource = MonitoredResource.of("custom", ImmutableMap.<String, String>of());
logging.setFlushSeverity(Severity.ERROR);
expectLastCall().once();
logging.setWriteSynchronicity(Synchronicity.ASYNC);
expectLastCall().once();
logging.write(ImmutableList.of(FINEST_ENHANCED_ENTRY), WriteOption.logName(LOG_NAME), WriteOption.resource(resource), WriteOption.labels(BASE_SEVERITY_MAP));
expectLastCall().once();
replay(options, logging);
LoggingEnhancer enhancer = new LoggingEnhancer() {
@Override
public void enhanceLogEntry(Builder builder) {
builder.addLabel("enhanced", "true");
}
};
Handler handler = new LoggingHandler(LOG_NAME, options, resource, Collections.singletonList(enhancer));
handler.setLevel(Level.ALL);
handler.setFormatter(new TestFormatter());
handler.publish(newLogRecord(Level.FINEST, MESSAGE));
}
use of java.util.logging.Handler in project google-cloud-java by GoogleCloudPlatform.
the class LoggingHandlerTest method testReportWriteError.
@Test
public void testReportWriteError() {
expect(options.getProjectId()).andReturn(PROJECT).anyTimes();
expect(options.getService()).andReturn(logging);
RuntimeException ex = new RuntimeException();
logging.setFlushSeverity(Severity.ERROR);
expectLastCall().once();
logging.setWriteSynchronicity(Synchronicity.ASYNC);
expectLastCall().once();
logging.write(ImmutableList.of(FINEST_ENTRY), DEFAULT_OPTIONS);
expectLastCall().andStubThrow(ex);
replay(options, logging);
ErrorManager errorManager = EasyMock.createStrictMock(ErrorManager.class);
errorManager.error(null, ex, ErrorManager.WRITE_FAILURE);
expectLastCall().once();
replay(errorManager);
Handler handler = new LoggingHandler(LOG_NAME, options);
handler.setLevel(Level.ALL);
handler.setErrorManager(errorManager);
handler.setFormatter(new TestFormatter());
handler.publish(newLogRecord(Level.FINEST, MESSAGE));
verify(errorManager);
}
use of java.util.logging.Handler in project jdk8u_jdk by JetBrains.
the class LoggingExceptionTest method main.
public static void main(String[] args) {
Handler handler = new ConsoleHandler();
Logger logger = Logger.getLogger("javax.management.modelmbean");
logger.addHandler(handler);
logger.setLevel(Level.FINEST);
try {
for (int i = 0; i < tests.length; i++) {
System.out.println(">>> DescriptorSupportLoggingTest: Test Case " + i);
DescriptorSupport ds;
String msg = "Instantiate " + tests[i];
System.out.println(msg);
switch(i) {
case 0:
ds = new DescriptorSupport();
break;
case 1:
ds = new DescriptorSupport(10);
break;
case 2:
ds = new DescriptorSupport(new DescriptorSupport().toXMLString());
break;
case 3:
ds = new DescriptorSupport("name1=value1", "name2=value2");
break;
case 4:
ds = new DescriptorSupport(new String[] { "name" }, new Object[] { "value" });
break;
case 5:
ds = new DescriptorSupport(new DescriptorSupport());
break;
case 6:
RequiredModelMBean mbean = new RequiredModelMBean();
NotificationListener nl = new NotificationListener() {
public void handleNotification(Notification notification, Object handback) {
}
};
mbean.addAttributeChangeNotificationListener(nl, null, null);
break;
default:
throw new AssertionError();
}
System.out.println(msg + " OK");
}
} catch (Exception e) {
System.out.println("Got unexpected exception = " + e);
String msg = "Test FAILED!";
System.out.println(msg);
throw new IllegalArgumentException(msg);
}
System.out.println("Test PASSED!");
}
use of java.util.logging.Handler in project geode by apache.
the class LogWrapper method cleanupLogger.
/**
* Removed all the handlers of the given {@link Logger} instance.
*
* @param logger {@link Logger} to be cleaned up.
*/
private static void cleanupLogger(Logger logger) {
if (logger != null) {
Handler[] handlers = logger.getHandlers();
for (Handler handler : handlers) {
handler.close();
logger.removeHandler(handler);
}
}
}
Aggregations