You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@logging.apache.org by Igor Deruga <i....@gmail.com> on 2018/07/22 22:37:08 UTC

LOG4J2-2256: GelfLayout does not allow to truncate short message to arbitrary length

Greetings,

I'm trying to work on this issue and add the possibility to format the
short and full messages of the GELF layout as needed. I consider this
functionality as vital for those who wish to migrate from Logback to Log4j2
(as it is in my case).

I would like to outline my approach and get some feedback before I create
my pull request, so if you have anything to suggest at all, please feel
free to do so.

I'm planning on extending the GELF layout with two new PluginAttribute
values, shortMessagePattern and fullMessagePattern that would hold the
strings compatible with PatternLayout. I'd keep an Optional-wrapped
PatternLayouts corresponding to these two attributes in the GelfLayoutClass
in order to format the full and short messages.
Inside the toText method, I'd delegate the output of the full and short
messages to those layouts, if present, or to the existing logic, if not.
The PatternLayout::encode method requires a ByteBufferDestination to write
into, so I'm coming up with something that would use ByteBuffer as an
interface between PatternLayout and StringBuilder of the GelfAppender. This
would take some time because the ByteBuffer is a new concept for me.

The particular questions that I have:
Is it ok if I delegate a portion of the job to the PatternLayout? It is
rather hard to isolate just the portion that I need to format the message,
so I guess I'm stuck with using the whole class (there seems to be no
utility class or some form of PatternFormmatterToStringBuilder class).

My guess is that apart from the regular unit tests, I'll need to add a
benchmark for the case when the new fields are non-null, but I'm kind of
lost in the benchmark framework... is there some documentation that I could
read first?

Thanks in advance!
Igor.