Skip to content

Commit

Permalink
Add enableLoggingFail option to the FailoverIntrospector
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo committed Oct 4, 2024
1 parent 1309439 commit e7106e5
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ FixtureMonkey sut = FixtureMonkey.builder()
.build();
```

생성에 실패하면 발생하는 로그를 보고싶지 않다면 생성자 파라미터 `enableLoggingFail`를 false로 설정하면 됩니다.

```java
FailoverIntrospector failoverIntrospector = new FailoverIntrospector(introspectors, false);
```

## PriorityConstructorArbitraryIntrospector
픽스쳐 몽키에서 기본으로 생성을 지원하지 않는 타입은 사용자 정의 `ArbitraryIntrospector`를 사용하면 생성할 수 있습니다.
하지만 픽스쳐 몽키에 익숙하지 않다면 `ArbitraryIntrospector`를 만들기는 어렵습니다.
Expand Down
6 changes: 6 additions & 0 deletions docs/content/v1.0.x-kor/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ menu:
docs:
weight: 100
---
sectionStart
## v.1.0.27
Add `enableLoggingFail` option as a constructor argument in `FailoverIntrospector`

sectionEnd

sectionStart
## v.1.0.26
Add `PriorityConstructorArbitraryIntrospector`
Expand Down
6 changes: 6 additions & 0 deletions docs/content/v1.0.x/docs/generating-objects/introspector.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ FixtureMonkey sut = FixtureMonkey.builder()
.build();
```

If you want to disable the fail log, you should set the constructor argument `enableLoggingFail` to false.

```java
FailoverIntrospector failoverIntrospector = new FailoverIntrospector(introspectors, false);
```

## PriorityConstructorArbitraryIntrospector
Types that Fixture Monkey does not support creating by default can be created using a custom `ArbitraryIntrospector`.
However, creating your own `ArbitraryIntrospector` can be difficult if you are not familiar with Fixture Monkey.
Expand Down
6 changes: 6 additions & 0 deletions docs/content/v1.0.x/release-notes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ menu:
docs:
weight: 100
---
sectionStart
## v.1.0.27
Add `enableLoggingFail` option as a constructor argument in `FailoverIntrospector`

sectionEnd

sectionStart
## v.1.0.26
Add `PriorityConstructorArbitraryIntrospector`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@ public final class FailoverIntrospector implements ArbitraryIntrospector {
private static final Logger LOGGER = LoggerFactory.getLogger(FailoverIntrospector.class);

private final List<ArbitraryIntrospector> introspectors;
private final boolean enableLoggingFail;

public FailoverIntrospector(List<ArbitraryIntrospector> introspectors) {
this(introspectors, true);
}

public FailoverIntrospector(List<ArbitraryIntrospector> introspectors, boolean enableLoggingFail) {
this.introspectors = introspectors;
this.enableLoggingFail = enableLoggingFail;
}

@Override
Expand All @@ -51,14 +57,16 @@ public ArbitraryIntrospectorResult introspect(ArbitraryGeneratorContext context)
results.add(new FailoverIntrospectorResult(introspector, result));
}
} catch (Exception ex) {
LOGGER.warn(
String.format(
"\"%s\" is failed to introspect \"%s\" type.",
introspector.getClass().getSimpleName(),
((Class<?>)context.getResolvedProperty().getType()).getName()
),
ex
);
if (enableLoggingFail) {
LOGGER.warn(
String.format(
"\"%s\" is failed to introspect \"%s\" type.",
introspector.getClass().getSimpleName(),
((Class<?>)context.getResolvedProperty().getType()).getName()
),
ex
);
}
// omitted
}
}
Expand All @@ -77,14 +85,16 @@ public Object combined() {
result = iterator.next();
return result.getResult().getValue().combined();
} catch (Exception ex) {
LOGGER.warn(
String.format(
"\"%s\" is failed to introspect \"%s\" type.",
Objects.requireNonNull(result).getIntrospector().getClass().getSimpleName(),
((Class<?>)context.getResolvedProperty().getType()).getName()
),
ex
);
if (enableLoggingFail) {
LOGGER.warn(
String.format(
"\"%s\" is failed to introspect \"%s\" type.",
Objects.requireNonNull(result).getIntrospector().getClass().getSimpleName(),
((Class<?>)context.getResolvedProperty().getType()).getName()
),
ex
);
}
// omitted
}
}
Expand All @@ -105,14 +115,16 @@ public Object rawValue() {
result = iterator.next();
return result.getResult().getValue().rawValue();
} catch (Exception ex) {
LOGGER.warn(
String.format(
"\"%s\" is failed to introspect type \"%s\"",
Objects.requireNonNull(result).getIntrospector().getClass().getSimpleName(),
((Class<?>)context.getResolvedProperty().getType()).getName()
),
ex
);
if (enableLoggingFail) {
LOGGER.warn(
String.format(
"\"%s\" is failed to introspect type \"%s\"",
Objects.requireNonNull(result).getIntrospector().getClass().getSimpleName(),
((Class<?>)context.getResolvedProperty().getType()).getName()
),
ex
);
}
// omitted
}
}
Expand Down

0 comments on commit e7106e5

Please sign in to comment.