question:
the printed result of my log is as follows:
[main] INFO Test-API input parameter =
I want to get a log like this: f9e287fad9e84cff8b2c2f2ed92adbe6 [main] INFO Test-API input parameter
1. My test class
import org.apache.log4j.MDC;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Test {
static Logger logger = LoggerFactory.getLogger(Test.class);
public static void main(String[] args) {
MDC.clear();
MDC.put("logid", "f9e287fad9e84cff8b2c2f2ed92adbe6");
MDC.put("merchant_id", 1);
MDC.put("siteName", "");
MDC.put("userName", "userwyh");
MDC.put("mobile", "110");
MDC.put("mchId", 12);
MDC.put("mchName", "");
logger.info("===");
}
2. My log4j profile:
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d {yy/MM/dd HH:mm:ss}% p% c {2}:% m% n
log4j.logger.com.rong360.crawler=info,console,info,warn,error,fatal
logging.path=e:/logs/crawler-meituan/logs
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%-d {yyyy-MM-dd HH:mm:ss,SSS} [% p] [% l] [% tblog% r] [% X {logid}] [% X {ip}] [% X {uri}] [% X {merchant_id}] [% X {user_id}]% m% n
log4j.appender.console.Threshold=INFO
log4j.appender.debug=com.rong360.crawler.log4j.Rong360DailyRollingFileAppender
log4j.appender.debug.layout=org.apache.log4j.PatternLayout
log4j.appender.debug.layout.ConversionPattern=%-d {yyyy-MM-dd HH:mm:ss, SSS} [% p] [% l] [% turi% r] [% X {logid}] [% X {ip}] [% X {uri}] [% X {merchant_id}] [% X {user_id}]% m% n
log4j.appender.debug.Threshold = DEBUG
log4j.appender.debug.append=true
log4j.appender.debug.File=debug.log
log4j.appender.info=com.rong360.crawler.log4j.Rong360DailyRollingFileAppender
log4j.appender.info.layout=org.apache.log4j.PatternLayout
log4j.appender.info.append=true
log4j.appender.info.layout.ConversionPattern=%-d {yyyy-MM-dd HH:mm:ss, SSS} [% p] [% l] [% logid% r] [% X {logid}] [% X {ip}] [% X {uri}] [% X {merchant_id}] [% X {user_id}]% m% n
log4j.appender.info.Threshold = INFO
log4j.appender.info.File=info.log
log4j.appender.warn=com.rong360.crawler.log4j.Rong360DailyRollingFileAppender
log4j.appender.warn.layout=org.apache.log4j.PatternLayout
log4j.appender.warn.layout.ConversionPattern=%-d {yyyy-MM-dd HH:mm:ss, SSS} [% p] [% l] [% turi% r] [% X {logid}] [% X {ip}] [% X {uri}] [% X {merchant_id}] [% X {user_id}]% m% n
log4j.appender.warn.Threshold = WARN
log4j.appender.warn.append=true
log4j.appender.warn.File=warn.log
log4j.appender.error=com.rong360.crawler.log4j.Rong360DailyRollingFileAppender
log4j.appender.error.layout=org.apache.log4j.PatternLayout
log4j.appender.error.layout.ConversionPattern=%-d {yyyy-MM-dd HH:mm:ss, SSS} [% p] [% l] [% turi% r] [% X {logid}] [% X {ip}] [% X {uri}] [% X {merchant_id}] [% X {user_id}]% m% n
log4j.appender.error.Threshold = ERROR
log4j.appender.error.append=true
log4j.appender.error.File=error.log
log4j.appender.fatal=com.rong360.crawler.log4j.Rong360DailyRollingFileAppender
log4j.appender.fatal.layout=org.apache.log4j.PatternLayout
log4j.appender.fatal.layout.ConversionPattern=%-d {yyyy-MM-dd HH:mm:ss, SSS} [% p] [% l] [% turi% r] [% X {logid}] [% X {ip}] [% X {uri}] [% X {merchant_id}] [% X {user_id}]% m% n
log4j.appender.fatal.Threshold = FATAL
log4j.appender.fatal.append=true
log4j.appender.fatal.File=fatal.log