diff --git a/docs/USERGUIDE.md b/docs/USERGUIDE.md index 3438dde..2e31670 100644 --- a/docs/USERGUIDE.md +++ b/docs/USERGUIDE.md @@ -461,12 +461,14 @@ Taikai.builder() Logging configuration involves specifying constraints related to logging frameworks and practices. -- **Ensure Logger Field Conforms to Standards**: Ensure that classes use a logger field of the specified type, with the correct name and modifiers. +- **Ensure Logger Field Conforms to Standards**: Ensure that classes use a logger field of the specified type, with the correct name and optionally required modifiers. ```java Taikai.builder() .namespace("com.company.project") .logging(logging -> logging + .loggersShouldFollowConventions(org.slf4j.Logger.class, "logger") + .loggersShouldFollowConventions("org.slf4j.Logger", "logger") .loggersShouldFollowConventions(org.slf4j.Logger.class, "logger", List.of(PRIVATE, FINAL)) .loggersShouldFollowConventions("org.slf4j.Logger", "logger", List.of(PRIVATE, FINAL))) .build() diff --git a/src/main/java/com/enofex/taikai/logging/LoggingConfigurer.java b/src/main/java/com/enofex/taikai/logging/LoggingConfigurer.java index 78e47d5..867df87 100644 --- a/src/main/java/com/enofex/taikai/logging/LoggingConfigurer.java +++ b/src/main/java/com/enofex/taikai/logging/LoggingConfigurer.java @@ -12,6 +12,7 @@ import com.enofex.taikai.configures.DisableableConfigurer; import com.tngtech.archunit.core.domain.JavaModifier; import java.util.Collection; +import java.util.List; public class LoggingConfigurer extends AbstractConfigurer { @@ -34,6 +35,28 @@ public LoggingConfigurer classesShouldUseLogger(String typeName, String regex, .should(haveFieldOfType(typeName)), configuration)); } + public LoggingConfigurer loggersShouldFollowConventions(String typeName, String regex) { + return loggersShouldFollowConventions(typeName, regex, List.of(), + defaultConfiguration()); + } + + public LoggingConfigurer loggersShouldFollowConventions(String typeName, String regex, + Configuration configuration) { + return loggersShouldFollowConventions(typeName, regex, List.of(), + configuration); + } + + public LoggingConfigurer loggersShouldFollowConventions(Class clazz, String regex) { + return loggersShouldFollowConventions(clazz.getName(), regex, List.of(), + defaultConfiguration()); + } + + public LoggingConfigurer loggersShouldFollowConventions(Class clazz, String regex, + Configuration configuration) { + return loggersShouldFollowConventions(clazz.getName(), regex, List.of(), + configuration); + } + public LoggingConfigurer loggersShouldFollowConventions(String typeName, String regex, Collection requiredModifiers) { return loggersShouldFollowConventions(typeName, regex, requiredModifiers, @@ -46,6 +69,7 @@ public LoggingConfigurer loggersShouldFollowConventions(Class clazz, String r defaultConfiguration()); } + public LoggingConfigurer loggersShouldFollowConventions(Class clazz, String regex, Collection requiredModifiers, Configuration configuration) { return loggersShouldFollowConventions(clazz.getName(), regex, requiredModifiers,