You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
775 B

3 years ago
  1. package ru.digitalbanana.demoresourceserver.config;
  2. import org.slf4j.*;
  3. import org.springframework.beans.factory.InjectionPoint;
  4. import org.springframework.context.annotation.*;
  5. import org.springframework.core.MethodParameter;
  6. import static java.util.Optional.*;
  7. import java.lang.reflect.Field;
  8. @Configuration
  9. public class LoggingConfiguration {
  10. @Bean
  11. @Scope("prototype")
  12. public Logger logger(final InjectionPoint ip) {
  13. return LoggerFactory.getLogger(of(ip.getMethodParameter())
  14. .<Class>map(MethodParameter::getContainingClass)
  15. .orElseGet(
  16. () -> ofNullable(ip.getField())
  17. .map(Field::getDeclaringClass)
  18. .orElseThrow(IllegalArgumentException::new)
  19. )
  20. );
  21. }
  22. }