Skip to content

Using custom pattern converters for JSON template layout #3117

Answered by vy
kf-ping asked this question in Q&A
Discussion options

You must be logged in to vote

I believe for custom Pattern Converters you rely on the format(LogEvent event, StringBuilder toAppendTo) method, so it did not occur to me to use ThreadContext, but that is a good idea. I assume you mean something like this?

@ConverterKeys({"header"})
public class HttpHeaderPatternConverter extends LogEventPatternConverter
{
    format(LogEvent event, StringBuilder toAppendTo)
    {
        toAppendTo.append("HttpHeaders: ");
        String httpHeaderValues =  ... process HTTP headers into String ... 
        toAppendTo.append(httpHeaderValues);

        ThreadContext.put("httpHeaders", httpHeaderValues);
    }
}

No. You better implement your custom thread context data provider.

Can I…

Replies: 1 comment 5 replies

Comment options

vy
Oct 24, 2024
Collaborator

You must be logged in to vote
5 replies
@kf-ping
Comment options

@vy
Comment options

vy Oct 25, 2024
Collaborator

@kf-ping
Comment options

@vy
Comment options

vy Oct 28, 2024
Collaborator

Answer selected by kf-ping
@kf-ping
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
layouts Affects one or more Layout plugins
2 participants