Skip to content

Commit

Permalink
Merge pull request #375 from jbaeck/main
Browse files Browse the repository at this point in the history
LOGMGR-315: SubstituteFilter is not applied to WrappedExtLogRecord
  • Loading branch information
jamezp authored Jan 17, 2023
2 parents 1de3c91 + 47ec437 commit 4ae258a
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 4ae258a

Please sign in to comment.