Skip to content

Commit

Permalink
Fix logback turbofilters configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Salac <[email protected]>
  • Loading branch information
richard-salac committed Jan 20, 2025
1 parent d12d84e commit b42b996
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 31 deletions.
2 changes: 1 addition & 1 deletion apiml-common/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<property name="apimlLogPattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS,UTC} %clr&lt;${logbackService:-${logbackServiceName}}:%thread:${PID:- }&gt; %magenta(%X{userid:-}) %cyan(%-5level) %clr\(\(%logger{15}\)\) %msg%n"/>

<turboFilter class="org.zowe.apiml.product.logging.UseridFilter"/>
<if condition='property("spring.config.activate.on-profile").contains("debug")||property("spring.config.activate.on-profile").contains("diag")||property("spring.config.activate.on-profile").contains("dev")'>
<if condition='property("spring.profiles.active").contains("debug")||property("spring.profiles.active").contains("diag")||property("spring.profiles.active").contains("dev")'>
<then>
</then>
<else>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,15 @@
* Solution is that ApimlLogger is enhancing its logs with Marker instances and this filter is providing
* adequate filtering.
*
* The filter is normally enabled (filtering), or disabled when the service is started with debug profile included
* in system variable spring.profiles.include
*/
public class LogLevelInfoFilter extends TurboFilter {

private static final String APIML_MARKER = "APIML-LOGGER";
private boolean isFilterActive;

public LogLevelInfoFilter() {
String profiles = System.getProperties().getProperty("spring.profiles.include");
isFilterActive = profiles == null || !(profiles.toLowerCase().contains("debug") || profiles.toLowerCase().contains("dev"));
}

@Override
public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {

if (isFilterActive
&& isLevelInfoOrLower(level)
if (isLevelInfoOrLower(level)
&& isInternalLogger(logger)
&& ( marker == null || !marker.getName().equals(APIML_MARKER))
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class LogLevelInfoFilterTest {

@BeforeEach
void setUp() {
System.getProperties().setProperty("spring.profiles.include", "");
filterInstance = new LogLevelInfoFilter();
}

Expand All @@ -42,22 +41,6 @@ void createActiveFilterInNormalMode() {
assertEquals(FilterReply.DENY, reply, "Filter does not filter INFO level messages");
}

@Test
void createInactiveFilterInDebugMode() {
System.getProperties().setProperty("spring.profiles.include", "blueberries,debug,diag");
LogLevelInfoFilter filter = new LogLevelInfoFilter();
FilterReply reply = filter.decide(null, (ch.qos.logback.classic.Logger) log, Level.INFO, "", null, null);
assertEquals(FilterReply.NEUTRAL, reply, "Filter should not filter when service not in debug mode");
}

@Test
void createInactiveFilterInDebugModeWithDevProfile() {
System.getProperties().setProperty("spring.profiles.include", "blueberries,dev,diag");
LogLevelInfoFilter filter = new LogLevelInfoFilter();
FilterReply reply = filter.decide(null, (ch.qos.logback.classic.Logger) log, Level.INFO, "", null, null);
assertEquals(FilterReply.NEUTRAL, reply, "Filter should not filter when service not in debug mode");
}

@Test
void filtersLevelTest() {

Expand Down
2 changes: 1 addition & 1 deletion caching-service/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<property name="apimlLogPattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS,UTC} %clr&lt;${logbackService:-${logbackServiceName}}:%thread:${PID:- }&gt; %magenta(%X{userid:-}) %cyan(%-5level) %clr\(\(%logger{15}\)\) %msg%n"/>

<turboFilter class="org.zowe.apiml.product.logging.UseridFilter"/>
<if condition='property("spring.config.activate.on-profile").contains("debug")||property("spring.config.activate.on-profile").contains("diag")||property("spring.config.activate.on-profile").contains("dev")'>
<if condition='property("spring.profiles.active").contains("debug")||property("spring.profiles.active").contains("diag")||property("spring.profiles.active").contains("dev")'>
<then>
</then>
<else>
Expand Down
2 changes: 1 addition & 1 deletion gateway-service/src/main/resources/logback-gateway.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<property name="apimlLogPattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS,UTC} %clr&lt;${logbackService:-${logbackServiceName}}:%thread:${PID:- }&gt; %magenta(%X{userid:-}) %cyan(%-5level) %clr\(\(%logger{15}\)\) %msg%n"/>

<turboFilter class="org.zowe.apiml.product.logging.UseridFilter"/>
<if condition='property("spring.config.activate.on-profile").contains("debug")||property("spring.config.activate.on-profile").contains("diag")||property("spring.config.activate.on-profile").contains("dev")'>
<if condition='property("spring.profiles.active").contains("debug")||property("spring.profiles.active").contains("diag")||property("spring.profiles.active").contains("dev")'>
<then>
</then>
<else>
Expand Down
3 changes: 2 additions & 1 deletion zaas-service/src/main/resources/logback-zaas.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
<property name="apimlLogPattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS,UTC} %clr&lt;${logbackService:-${logbackServiceName}}:%thread:${PID:- }&gt; %magenta(%X{userid:-}) %cyan(%-5level) %clr\(\(%logger{15}\)\) %msg%n"/>

<turboFilter class="org.zowe.apiml.product.logging.UseridFilter"/>
<if condition='property("spring.config.activate.on-profile").contains("debug")||property("spring.config.activate.on-profile").contains("diag")||property("spring.config.activate.on-profile").contains("dev")'>
<if condition='property("spring.profiles.active").contains("debug")||property("spring.profiles.active").contains("diag")||property("spring.profiles.active").contains("dev")'>
<then>
<turboFilter class="org.zowe.apiml.product.logging.LogLevelInfoFilter"/>
</then>
<else>
<turboFilter class="org.zowe.apiml.product.logging.LogLevelInfoFilter"/>
Expand Down

0 comments on commit b42b996

Please sign in to comment.