How can I change log4j behaviour when it formats parameters in a log line? -
log4j allows specify log string , objects separately. example:
import org.slf4j.logger; import org.slf4j.loggerfactory; public class mylogger { private static final logger logger = loggerfactory.getlogger(mylogger.class); public static void main(string [] args) { logger.info("this number {} , string {}", 5, "blah!"); } }
results in output
this number 5 , string blah!
i'd know if can tell log4j print parameters surrounded quotes every time prints log line . same piece of code above:
logger.info("this number {} , string {}", 5, "blah!");
would output:
this number "5" , string "blah!"
what want changing log4j behaviour, not call logger method (logger.info(...)). problem i'm calling logger in thousands of places , changing calls isn't practical.
you need add quotes escape character i.e. \
either in original string before , after parameter brackets or in arguments if string. below examples;
logger.info("args 1 \"{}\" , 2 \"{}\"", "blah!!", 4);
outputargs 1 "blah!!" , 2 "4"
.logger.info("args 1 {} , 2 {}", "\"blah!!\"", 4);
outputargs 1 "blah!!" , 2 4
Comments
Post a Comment