With single ILoggingEvent.getFormattedMessage() is null logging becomes completely broken
gavenkoa opened this issue · 0 comments
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)