Log4j is a logging tool that is commonly used in programs and has five levels: the level of log4J
Today’s question: What do I do when I print three or more parameters? Straight to the basics:
Logger. The info (" tryGetCustomerByJdPinAndDepartNo - into the ginseng jdPin: {}, departNo: {}, init; {}", jdPin, departNo,JSON.toJSONString(init));Copy the code
Error message:
The reason:
Find the source: logger. class
The method structure of InfoD is shown below:
void info(String var1); void info(String var1, Object var2); void info(String var1, Object var2, Object var3); void info(String var1, Object[] var2); void info(String var1, Throwable var2); boolean isInfoEnabled(Marker var1); void info(Marker var1, String var2); void info(Marker var1, String var2, Object var3); void info(Marker var1, String var2, Object var3, Object var4); void info(Marker var1, String var2, Object[] var3); void info(Marker var1, String var2, Throwable var3);
Copy the code
Conclusion: With 3 or more parameters, another method is needed:
Construct an array of objects
Logger. The info (" tryGetCustomerByJdPinAndDepartNo - into the ginseng jdPin: {}, departNo: {}, init; {}", new String[] {jdPin, departNo,JSON.toJSONString(init)});Copy the code