Skip to content

Commit

Permalink
Add new overloading loggersShouldFollowConventions rules without requ…
Browse files Browse the repository at this point in the history
…ired modifiers
  • Loading branch information
mnhock authored and mnhock committed Sep 23, 2024
1 parent b48e4a6 commit 4f9db44
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/USERGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/enofex/taikai/logging/LoggingConfigurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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<JavaModifier> requiredModifiers) {
return loggersShouldFollowConventions(typeName, regex, requiredModifiers,
Expand All @@ -46,6 +69,7 @@ public LoggingConfigurer loggersShouldFollowConventions(Class<?> clazz, String r
defaultConfiguration());
}


public LoggingConfigurer loggersShouldFollowConventions(Class<?> clazz, String regex,
Collection<JavaModifier> requiredModifiers, Configuration configuration) {
return loggersShouldFollowConventions(clazz.getName(), regex, requiredModifiers,
Expand Down

0 comments on commit 4f9db44

Please sign in to comment.