Skip to content

Commit aee5ef8

Browse files
committed
Adjust troubleshooting header
1 parent 23a18f5 commit aee5ef8

File tree

2 files changed

+10
-29
lines changed

2 files changed

+10
-29
lines changed

on-demand/on-demand-spring-boot-starter-grpc/src/main/java/no/entur/logging/cloud/spring/ondemand/grpc/GrpcOndemandLoggingAutoConfiguration.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,23 +129,13 @@ public GrpcLoggingScopeFilter toFilter(String serviceName, List<String> methodNa
129129

130130
LOGGER.info("Configure GRPC {} troubleshooting {} logging for headers {}", methodNames.isEmpty() ? serviceName : serviceName + methodNames, troubleshoot.getLevel(), troubleshootHeaderNames);
131131

132-
// troubleshooting: to take effect, the troubleshooting must be
133-
// - lower than success, and/or
134-
// - lower than failure
132+
// troubleshooting: lower the success / failure level
135133
Level troubleShootAlwaysLogLevel = toLevel(troubleshoot.getLevel());
136-
if(troubleShootAlwaysLogLevel.toInt() > alwaysLogLevel.toInt()) {
137-
filter.setTroubleshootQueuePredicate( (e) -> e.getLevel().toInt() < alwaysLogLevel.toInt());
138-
} else {
139-
filter.setTroubleshootQueuePredicate( (e) -> e.getLevel().toInt() < troubleShootAlwaysLogLevel.toInt());
140-
}
141-
142-
Level troubleShootOptionallyLogLevel = troubleShootAlwaysLogLevel;
143-
if( troubleShootOptionallyLogLevel.toInt() > optionallyLogLevel.toInt()) {
144-
filter.setTroubleshootIgnorePredicate( (e) -> e.getLevel().toInt() < optionallyLogLevel.toInt());
145-
} else {
146-
filter.setTroubleshootIgnorePredicate( (e) -> e.getLevel().toInt() < troubleShootOptionallyLogLevel.toInt());
147-
}
134+
int alwaysLogLevelWhenTroubleShooting = Math.min(alwaysLogLevel.toInt(), troubleShootAlwaysLogLevel.toInt());
135+
filter.setTroubleshootQueuePredicate((e) -> e.getLevel().toInt() < alwaysLogLevelWhenTroubleShooting);
148136

137+
int optionalLogLevelWhenTroubleShooting = Math.min(optionallyLogLevel.toInt(), troubleShootAlwaysLogLevel.toInt());
138+
filter.setTroubleshootIgnorePredicate((e) -> e.getLevel().toInt() < optionalLogLevelWhenTroubleShooting);
149139
} else {
150140
filter.setGrpcHeaderPresentPredicate((e) -> false);
151141
filter.setTroubleshootQueuePredicate((e) -> false);

on-demand/on-demand-spring-boot-starter-web/src/main/java/no/entur/logging/cloud/spring/ondemand/web/GcpWebOndemandLoggingAutoConfiguration.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,13 @@ public HttpLoggingScopeFilter toFilter(String matcher, OndemandSuccess success,
129129

130130
LOGGER.info("Configure {} troubleshooting {} logging for headers {}", matcher == null ? "default" : matcher, troubleshoot.getLevel().toString(), troubleshootHeaderNames);
131131

132-
// troubleshooting: to take effect, the troubleshooting must be
133-
// - lower than success, and/or
134-
// - lower than failure
132+
// troubleshooting: lower the success / failure level
135133
Level troubleShootAlwaysLogLevel = toLevel(troubleshoot.getLevel());
136-
if (troubleShootAlwaysLogLevel.toInt() > alwaysLogLevel.toInt()) {
137-
filter.setTroubleshootQueuePredicate((e) -> e.getLevel().toInt() < alwaysLogLevel.toInt());
138-
} else {
139-
filter.setTroubleshootQueuePredicate((e) -> e.getLevel().toInt() < troubleShootAlwaysLogLevel.toInt());
140-
}
134+
int alwaysLogLevelWhenTroubleShooting = Math.min(alwaysLogLevel.toInt(), troubleShootAlwaysLogLevel.toInt());
135+
filter.setTroubleshootQueuePredicate((e) -> e.getLevel().toInt() < alwaysLogLevelWhenTroubleShooting);
141136

142-
Level troubleShootOptionallyLogLevel = troubleShootAlwaysLogLevel;
143-
if (troubleShootOptionallyLogLevel.toInt() > optionallyLogLevel.toInt()) {
144-
filter.setTroubleshootIgnorePredicate((e) -> e.getLevel().toInt() < optionallyLogLevel.toInt());
145-
} else {
146-
filter.setTroubleshootIgnorePredicate((e) -> e.getLevel().toInt() < troubleShootOptionallyLogLevel.toInt());
147-
}
137+
int optionalLogLevelWhenTroubleShooting = Math.min(optionallyLogLevel.toInt(), troubleShootAlwaysLogLevel.toInt());
138+
filter.setTroubleshootIgnorePredicate((e) -> e.getLevel().toInt() < optionalLogLevelWhenTroubleShooting);
148139
} else {
149140
filter.setTroubleshootQueuePredicate((e) -> false);
150141
filter.setTroubleshootIgnorePredicate((e) -> false);

0 commit comments

Comments
 (0)