use of cn.taketoday.logging.Logger in project today-infrastructure by TAKETODAY.
the class CustomizableTraceInterceptorTests method testExceptionPathLogsCorrectly.
@Test
public void testExceptionPathLogsCorrectly() throws Throwable {
MethodInvocation methodInvocation = mock(MethodInvocation.class);
IllegalArgumentException exception = new IllegalArgumentException();
given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString"));
given(methodInvocation.getThis()).willReturn(this);
given(methodInvocation.proceed()).willThrow(exception);
Logger log = mock(Logger.class);
given(log.isTraceEnabled()).willReturn(true);
CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);
assertThatIllegalArgumentException().isThrownBy(() -> interceptor.invoke(methodInvocation));
verify(log).trace(anyString());
verify(log).trace(anyString(), eq(exception));
}
use of cn.taketoday.logging.Logger in project today-infrastructure by TAKETODAY.
the class ResourceHttpMessageWriter method writeResource.
private Mono<Void> writeResource(Resource resource, ResolvableType type, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, Map<String, Object> hints) {
HttpHeaders headers = message.getHeaders();
MediaType resourceMediaType = getResourceMediaType(mediaType, resource, hints);
headers.setContentType(resourceMediaType);
if (headers.getContentLength() < 0) {
long length = lengthOf(resource);
if (length != -1) {
headers.setContentLength(length);
}
}
return zeroCopy(resource, null, message, hints).orElseGet(() -> {
Mono<Resource> input = Mono.just(resource);
DataBufferFactory factory = message.bufferFactory();
Flux<DataBuffer> body = this.encoder.encode(input, factory, type, resourceMediaType, hints);
if (logger.isDebugEnabled()) {
body = body.doOnNext(buffer -> Hints.touchDataBuffer(buffer, hints, logger));
}
return message.writeWith(body);
});
}
use of cn.taketoday.logging.Logger in project today-infrastructure by TAKETODAY.
the class LoggingCacheErrorHandlerTests method handleGetCacheErrorLogsAppropriateMessage.
@Test
void handleGetCacheErrorLogsAppropriateMessage() {
Logger logger = mock(Logger.class);
LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(logger, false);
handler.handleCacheGetError(new RuntimeException(), new NoOpCache("NOOP"), "key");
verify(logger).warn("Cache 'NOOP' failed to get entry with key 'key'");
}
use of cn.taketoday.logging.Logger in project today-infrastructure by TAKETODAY.
the class LoggingCacheErrorHandlerTests method handlePutCacheErrorLogsAppropriateMessage.
@Test
void handlePutCacheErrorLogsAppropriateMessage() {
Logger logger = mock(Logger.class);
LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(logger, false);
handler.handleCachePutError(new RuntimeException(), new NoOpCache("NOOP"), "key", new Object());
verify(logger).warn("Cache 'NOOP' failed to put entry with key 'key'");
}
Aggregations