ecs-logging-java icon indicating copy to clipboard operation
ecs-logging-java copied to clipboard

Add the possibility to process or transform the message

Open fapena-galileo opened this issue 3 years ago • 1 comments
trafficstars

I need to be able to transform some messages. For example obfuscate some information. I want to be able to do that at the encoder level and not before on several components.

Now a days, the encode method add the message using event.getFormattedMessage()

It could be very useful if we can add something similar to the following at the ECSEncoder class:

/**
 * Subclasses can override this to format the message (for example to obfuscate some fields.)
 * @param event The event to be logged
 * @return The message processed. By default, this method return the message without any modification
 */
protected String processMessage (ILoggingEvent event){
   return event.getFormattedMessage();
}

And at the encode method

EcsJsonSerializer.serializeFormattedMessage(builder, processMessage(event));

What do you think?

The method name could be process, transform, or just getMessage...

fapena-galileo avatar Dec 30 '21 13:12 fapena-galileo

I think this is already supported with https://github.com/elastic/ecs-logging-java/pull/220

ChristianCiach avatar Jun 24 '24 12:06 ChristianCiach