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

With single ILoggingEvent.getFormattedMessage() is null logging becomes completely broken #63

Open
gavenkoa opened this issue Dec 11, 2019 · 0 comments

Comments

@gavenkoa
Copy link

gavenkoa commented Dec 11, 2019

Just do:

log.info(null);

and forget about delivering messages to ES until you reboot app ))

The problem is in:

            String formattedMessage = event.getFormattedMessage();
            if (settings.getMaxMessageSize() > 0 && formattedMessage.length() > settings.getMaxMessageSize()) {
                formattedMessage = formattedMessage.substring(0, settings.getMaxMessageSize()) + "..";
            }

formattedMessage.length() generates NPE.

AbstractElasticsearchPublisher is implemented in so shitty way that internals of JsonGenerator is stuck in broken state and can't heal.

JsonGenerator uses WriterBasedJsonGenerator and on

	private void serializeIndexString(JsonGenerator gen, T event) throws IOException {
		gen.writeStartObject();

writeStartObject() fail on internal check _verifyValueWrite("start an object"); as we are JsonWriteContext is at type == 2 and gotName == false so check fails:

    public int writeValue() {
        // Most likely, object:
        if (_type == TYPE_OBJECT) {
            if (!_gotName) {
                return STATUS_EXPECT_NAME;

In case of serialization errors JsonGenerator should be completely reinitialized or reset instead of reusing with broken intermediate state.

Following stacktrace is from a bit edited sources, ClassicElasticsearchPublisher is in original form:

java.lang.NullPointerException: null
	at com.internetitem.logback.elasticsearch.ClassicElasticsearchPublisher.serializeCommonFields(ClassicElasticsearchPublisher.java:37)
	at com.internetitem.logback.elasticsearch.ClassicElasticsearchPublisher.serializeCommonFields(ClassicElasticsearchPublisher.java:17)
	at com.internetitem.logback.elasticsearch.AbstractElasticsearchPublisher.serializeEvent(AbstractElasticsearchPublisher.java:211)
	at com.internetitem.logback.elasticsearch.AbstractElasticsearchPublisher.serializeEvents(AbstractElasticsearchPublisher.java:190)
	at com.internetitem.logback.elasticsearch.AbstractElasticsearchPublisher.run(AbstractElasticsearchPublisher.java:154)
	at java.base/java.lang.Thread.run(Thread.java:834)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant