use of org.slf4j.event.LoggingEvent in project bookkeeper by apache.
the class LoggerOutput method apply.
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
LoggerContext lc = (LoggerContext) LogManager.getContext(false);
logAppender = spy(NullAppender.createAppender(UUID.randomUUID().toString()));
logAppender.start();
lc.getConfiguration().addAppender(logAppender);
lc.getRootLogger().addAppender(lc.getConfiguration().getAppender(logAppender.getName()));
lc.updateLoggers();
try {
base.evaluate();
if (!logEventExpectations.isEmpty()) {
verify(logAppender, atLeastOnce()).append(logEventCaptor.capture());
List<LoggingEvent> logEvents = logEventCaptor.getAllValues().stream().map(LoggerOutput::toSlf4j).collect(Collectors.toList());
for (Consumer<List<LoggingEvent>> expectation : logEventExpectations) {
expectation.accept(logEvents);
}
}
} finally {
lc.getRootLogger().removeAppender(lc.getConfiguration().getAppender(logAppender.getName()));
lc.updateLoggers();
logEventExpectations.clear();
logEventCaptor = null;
}
}
};
}
use of org.slf4j.event.LoggingEvent in project opentelemetry-java by open-telemetry.
the class OtlpHttpLogExporterTest method testServerError.
@Test
@SuppressLogger(OkHttpExporter.class)
void testServerError() {
server.enqueue(buildResponse(HttpStatus.INTERNAL_SERVER_ERROR, Status.newBuilder().setMessage("Server error!").build()));
OtlpHttpLogExporter exporter = builder.build();
exportAndAssertResult(exporter, /* expectedResult= */
false);
LoggingEvent log = logs.assertContains("Failed to export logs. Server responded with HTTP status code 500. Error message: Server error!");
assertThat(log.getLevel()).isEqualTo(Level.WARN);
}
use of org.slf4j.event.LoggingEvent in project opentelemetry-java by open-telemetry.
the class OtlpHttpMetricExporterTest method testServerError.
@Test
void testServerError() {
server.enqueue(buildResponse(HttpStatus.INTERNAL_SERVER_ERROR, Status.newBuilder().setMessage("Server error!").build()));
OtlpHttpMetricExporter exporter = builder.build();
exportAndAssertResult(exporter, /* expectedResult= */
false);
LoggingEvent log = logs.assertContains("Failed to export metrics. Server responded with HTTP status code 500. Error message: Server error!");
assertThat(log.getLevel()).isEqualTo(Level.WARN);
}
use of org.slf4j.event.LoggingEvent in project opentelemetry-java by open-telemetry.
the class OtlpHttpMetricExporterTest method testServerErrorParseError.
@Test
void testServerErrorParseError() {
server.enqueue(HttpResponse.of(HttpStatus.INTERNAL_SERVER_ERROR, APPLICATION_PROTOBUF, "Server error!"));
OtlpHttpMetricExporter exporter = builder.build();
exportAndAssertResult(exporter, /* expectedResult= */
false);
LoggingEvent log = logs.assertContains("Failed to export metrics. Server responded with HTTP status code 500. Error message: Unable to parse response body, HTTP status message:");
assertThat(log.getLevel()).isEqualTo(Level.WARN);
}
use of org.slf4j.event.LoggingEvent in project opentelemetry-java by open-telemetry.
the class ContextTest method closingScopeWhenNotActiveIsLogged.
@Test
public void closingScopeWhenNotActiveIsLogged() {
Context initial = Context.current();
Context context = initial.with(ANIMAL, "cat");
try (Scope scope = context.makeCurrent()) {
Context context2 = context.with(ANIMAL, "dog");
try (Scope ignored = context2.makeCurrent()) {
assertThat(Context.current().get(ANIMAL)).isEqualTo("dog");
scope.close();
}
}
assertThat(Context.current()).isEqualTo(initial);
LoggingEvent log = logs.assertContains("Context in storage not the expected context");
assertThat(log.getLevel()).isEqualTo(Level.DEBUG);
}
Aggregations