Skip to content

Commit

Permalink
LOGMGR-315: SubstituteFilter is not applied to WrappedExtLogRecord
Browse files Browse the repository at this point in the history
o Initial implementation and test
o https://issues.redhat.com/browse/LOGMGR-315
  • Loading branch information
jbaeck committed Jan 17, 2023
1 parent 1de3c91 commit 47ec437
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/org/jboss/logmanager/WrappedExtLogRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ public void setMessage(final String message) {
orig.setMessage(message);
}

@Override
public void setMessage(String message, FormatStyle formatStyle) {
super.setMessage(message, formatStyle);
orig.setMessage(message);
}

public Object[] getParameters() {
return orig.getParameters();
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/org/jboss/logmanager/FilterTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,27 @@ public void substituteFilterExceptionNullMessageTest(){
assertEquals("null", logRecord.getFormattedMessage());
}

@Test
public void substitutionFilterWithLogRecord(){
final AtomicReference<String> result = new AtomicReference<String>();
final Handler handler = new MessageCheckingHandler(result);
final Logger logger = Logger.getLogger("filterTest");
final Filter filter = new SubstituteFilter(Pattern.compile("test"),"lunch",true);

logger.setUseParentHandlers(false);
logger.addHandler(handler);
logger.setLevel(Level.INFO);
logger.setFilter(filter);
handler.setLevel(Level.INFO);

final LogRecord record = new LogRecord(Level.INFO,"{0}");
record.setLoggerName("filterTest");
record.setParameters(new Object[]{"test"});

logger.log(record);
assertEquals("The substitution was not correctly applied","lunch",result.get());
}



private static final class MessageCheckingHandler extends Handler {
Expand Down

0 comments on commit 47ec437

Please sign in to comment.