How do I print a key/value pair on a log4j entry only if the value is set on MDC?
For example, I currently have the following pattern:
%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - client=%X{client} %m%n
I'd like to print the "client=" part only if there is a value on MDC for this key.
For example, when starting my program, there will be no client logged in, so logs would be recorded using this pattern:
%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
However, after the client has logged in (and after I have set the MDC with a "client" key), I need to print it using the following:
%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - client=%X{client} %m%n
Is there such "conditional pattern" on log4j?
Thank you