> On Mar 15, 2020, at 2:10 PM, Volkan Yazıcı <[email protected]> wrote:
>
> On Sun, Mar 15, 2020 at 6:03 PM Ralph Goers <[email protected]>
> wrote:
>> After looking at the code I am sure there is something
>> wrong with the logic. While you can set property
>> log4j2.enable.direct.encoders to true or false it
>> uses the same Encoder in either case.
>
> I am a little bit puzzled here. Which particular "logic" are you
> referring to exactly? The following in AbstractStringLayout?
AbstractLayout has
public void encode(final LogEvent event, final ByteBufferDestination
destination) {
final byte[] data = toByteArray(event);
destination.writeBytes(data, 0, data.length);
}
PaternLayout implements this as
@Override
public void encode(final LogEvent event, final ByteBufferDestination
destination) {
if (!(eventSerializer instanceof Serializer2)) {
super.encode(event, destination);
return;
}
final StringBuilder text = toText((Serializer2) eventSerializer, event,
getStringBuilder());
final Encoder<StringBuilder> encoder = getStringBuilderEncoder();
encoder.encode(text, destination);
trimToMaxSize(text);
}
>> As for why it is not a class member variable, that would
>> be because it wouldn’t be thread-safe if it was. The encoder
>> is a member of PatternLayout and multiple threads can be
>> using the same PatternLayout at the same time. That said,
>> even then I’m not sure why it has to be synchronized. Will
>> the ByteBuffer be manipulated from other threads while the
>> Layout is being rendered?
>
> That was exactly the question in my mind. I had the impression that
> TextEncoderHelper.encodeText() is supposed to take the necessary
> synchronization measures.
>
> BTW, LockingStringBuilderEncoder is not used anywhere, right? Am I
> missing something?
I also don’t see it used anywhere.
>
> Speaking of ENABLE_DIRECT_ENCODERS flag, what does it exactly mean
> when it's set to false? That is, if my layout can perfectly drain its
> output into a ByteBufferDestination without any TLAs or such, what is
> the point of disabling it because user has just requested that?
I would have assumed it would have allowed for different implementations. But
using true/false isn’t the way to do that. I didn’t implement this so I am not
sure why it exists as it does.
Ralph