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 6f748f0
Showing 1 changed file with 36 additions and 24 deletions.
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 6f748f0

Please sign in to comment.