使用 log4j1,我能够控制单个记录器级别,但属性语句似乎不适用于 log4j2。我将 rootLogger 级别设置为 DEBUG,并希望通过 commons-logging 抑制来自 Authorize.net 的大量调试日志。我正在尝试从 http 标头和线路日志中将级别设置为 WARN。
这是详细配置记录器的 log4j 文档 (参考“配置 Log4J”)
这是一个示例日志输出:
2019-01-01 17:00:01 EST DEBUG org.apache.http.headers http-outgoing-0 << Content-Type: application/xml; charset=utf-8
2019-01-01 17:00:01 EST DEBUG org.apache.http.headers http-outgoing-0 << X-OPNET-Transaction-Trace: a2_5ed1139b-1533-463c-811d-a5ed796d44e7-11076-21806894
2019-01-01 17:00:01 EST DEBUG org.apache.http.headers http-outgoing-0 << Access-Control-Allow-Credentials: true
2019-01-01 17:00:01 EST DEBUG org.apache.http.headers http-outgoing-0 << Access-Control-Allow-Headers: x-requested-with,cache-control,content-type,origin,method,SOAPAction
2019-01-01 17:05:31 EST DEBUG org.apache.http.wire http-outgoing-0 >> " <transactionRequest>[\n]"
2019-01-01 17:05:31 EST DEBUG org.apache.http.wire http-outgoing-0 >> " <transactionType>authCaptureTransaction</transactionType>[\n]"
2019-01-01 17:05:31 EST DEBUG org.apache.http.wire http-outgoing-0 >> " <amount>500</amount>[\n]"
2019-01-01 17:05:31 EST DEBUG org.apache.http.wire http-outgoing-0 >> " <payment>[\n]"
2019-01-01 17:05:31 EST DEBUG org.apache.http.wire http-outgoing-0 >> " <creditCard>[\n]"
2019-01-01 17:05:31 EST DEBUG org.apache.http.wire http-outgoing-0 >> " <cardNumber>4242424242424242</cardNumber>[\n]"
2019-01-01 17:05:31 EST DEBUG org.apache.http.wire http-outgoing-0 >> " <expirationDate>0822</expirationDate>[\n]"
2019-01-01 17:05:31 EST DEBUG org.apache.http.wire http-outgoing-0 >> " </creditCard>[\n]"
2019-01-01 17:05:31 EST DEBUG org.apache.http.wire http-outgoing-0 >> " </payment>[\n]"
2019-01-01 17:05:31 EST DEBUG org.apache.http.wire http-outgoing-0 >> " </transactionRequest>[\n]"
这是我当前的 log4j2.properties 文件:
# Tell the root logger what appenders and level to use
rootLogger.level = DEBUG
rootLogger.appenderRefs = console, file
rootLogger.appenderRef.console.ref = console
rootLogger.appenderRef.file.ref = file
appenders = console, file
##### Authorize.net #####
# Controls detailed wire protocol
log4j.logger.org.apache.http.wire=WARN
# Controls headers (good for debugging)
log4j.logger.org.apache.http.headers=WARN
# Controls http context (what you are sending and geting)
log4j.logger.org.apache.http=WARN
# Controls htmlunit details
log4j.logger.com.gargoylesoftware.htmlunit=WARN
##### Console Appender #####
appender.console.name = console
appender.console.type = Console
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss z} %-5p %c %m%n
##### File Appender #####
appender.file.name = file
appender.file.type = File
appender.file.fileName = mylog.log
appender.file.layout.type = PatternLayout
appender.file.layout.pattern = %d{yyyy-MM-dd HH:mm:ss z} %-5p %c %m%n