package ru.digitalbanana.demoresourceserver.config;
|
|
|
|
import org.slf4j.*;
|
|
import org.springframework.beans.factory.InjectionPoint;
|
|
import org.springframework.context.annotation.*;
|
|
import org.springframework.core.MethodParameter;
|
|
|
|
import static java.util.Optional.*;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
@Configuration
|
|
public class LoggingConfiguration {
|
|
@Bean
|
|
@Scope("prototype")
|
|
public Logger logger(final InjectionPoint ip) {
|
|
return LoggerFactory.getLogger(of(ip.getMethodParameter())
|
|
.<Class>map(MethodParameter::getContainingClass)
|
|
.orElseGet(
|
|
() -> ofNullable(ip.getField())
|
|
.map(Field::getDeclaringClass)
|
|
.orElseThrow(IllegalArgumentException::new)
|
|
)
|
|
);
|
|
}
|
|
}
|