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

Make AbstractJsonPatternParser throw an exception for invalid pattern instead of logging an ERROR status #691

Merged
merged 14 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from 13 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Objects;

import net.logstash.logback.pattern.AbstractJsonPatternParser;
import net.logstash.logback.pattern.AbstractJsonPatternParser.JsonPatternException;
import net.logstash.logback.pattern.NodeWriter;

import ch.qos.logback.access.spi.IAccessEvent;
Expand Down Expand Up @@ -79,19 +80,28 @@ public void start() {
if (jsonFactory == null) {
throw new IllegalStateException("JsonFactory has not been set");
}
initializeNodeWriter();

try {
this.nodeWriter = initializeNodeWriter();
} catch (JsonPatternException e) {
this.nodeWriter = null;
addError("Invalid [pattern]: " + e.getMessage(), e);
}

super.start();
}


/**
* Parses the pattern into a {@link NodeWriter}.
*
* @return a {@link NodeWriter}
* @throws JsonPatternException thrown in case of invalid pattern
*/
private void initializeNodeWriter() {
private NodeWriter<Event> initializeNodeWriter() throws JsonPatternException {
AbstractJsonPatternParser<Event> parser = createParser(this.jsonFactory);
parser.setOmitEmptyFields(omitEmptyFields);
this.nodeWriter = parser.parse(pattern);
return parser.parse(pattern);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class AccessEventPatternJsonProvider extends AbstractPatternJsonProvider<

@Override
protected AbstractJsonPatternParser<IAccessEvent> createParser(JsonFactory jsonFactory) {
return new AccessEventJsonPatternParser(this, jsonFactory);
return new AccessEventJsonPatternParser(getContext(), jsonFactory);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class LoggingEventPatternJsonProvider extends AbstractPatternJsonProvider

@Override
protected AbstractJsonPatternParser<ILoggingEvent> createParser(JsonFactory jsonFactory) {
return new LoggingEventJsonPatternParser(this, jsonFactory);
return new LoggingEventJsonPatternParser(getContext(), jsonFactory);
}

}
Loading