Structural replace for log statements
I am using a logging library which supports logging varargs of key value pairs e.g.
log.info("a_string", "another_string", "key1", value1, "key2", value2, "key3", value3);
I am trying to use SSR to convert these log statements to the log statement supported by slf4j. So I want to convert above statement to,
log.info("a_string another_string key1={} key2={} key3={}", value1, value2, value3);
Since my logging library supports passing varargs of key-value pairs, the only way I found was to have multiple SSR templates to support the slf4j migration i.e. one SSR template each supporting 1 key-value pair, 2 key-value pairs, 3 key-value pair and so on. Is there a way to write more generic SSR template to detect and convert variable number of key-value pairs into the format expected by slf4j?
Thanks,
Amol
Please sign in to leave a comment.
I found the solution to this. Its hacky, but works.