使用Log4j扩展发送消息报错。
Closed this issue · 1 comments
log4j.properties
log4j.logger.testLog=debug,testMessage
log4j.additivity.testMessage=true
log4j.appender.testMessage=com.taobao.metamorphosis.client.extension.log4j.StreamAppender
log4j.appender.testMessage.topic=msg
log4j.appender.testMessage.zkConnect=192.168.111.140:2181
log4j.appender.testMessage.EncodeType=1
log4j.appender.testMessage.BufferedIO=true
log4j.appender.testMessage.DatePattern='.'yyyy-MM-dd_HH
log4j.appender.testMessage.File=../../logs/test.log
log4j.appender.testMessage.layout=org.apache.log4j.PatternLayout
log4j.appender.testMessage.layout.ConversionPattern=%d{MM-dd HH:mm:ss} - %m%n
Logtest.java
public class Logtest {
static final Log log = LogFactory.getLog("testLog");
public void printLog(){
log.info("just a test");
}
public static void main(String[] args) throws Exception {
new Logtest().printLog();
}
}
console
log4j:WARN No such property [datePattern] in com.taobao.metamorphosis.client.extension.log4j.StreamAppender.
log4j:WARN No such property [file] in com.taobao.metamorphosis.client.extension.log4j.StreamAppender.
log4j:WARN No such property [bufferedIO] in com.taobao.metamorphosis.client.extension.log4j.StreamAppender.
log4j:ERROR No output stream or file set for the appender named [testMessage].
Process finished with exit code 0
找到原因了,改成下边的配置就好了
log4j.properties
log4j.logger.testLog=info, testMessage
log4j.additivity.testMessage=false
log4j.appender.testMessage=com.taobao.metamorphosis.client.extension.log4j.DailyRollingFileStreamAppender
log4j.appender.testMessage.topic=msg
log4j.appender.testMessage.zkConnect=192.168.111.140:2181
log4j.appender.testMessage.BufferedIO=true
log4j.appender.testMessage.DatePattern='.'yyyy-MM-dd_HH
log4j.appender.testMessage.File=../../logs/test.log
log4j.appender.testMessage.layout=org.apache.log4j.PatternLayout
log4j.appender.testMessage.layout.ConversionPattern=%d{MM-dd HH:mm:ss} - %m%n
log4j.appender.testMessage.Append=true