Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LOGMGR-315: SubstituteFilter is not applied to WrappedExtLogRecord #375

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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