java - Kafka Log4j appender not sending messages -
i quite new ot apache kafka , log4j. trying send log messages kafka. here log4j properties file
log4j.rootlogger=info, stdout log4j.appender.stdout=org.apache.log4j.consoleappender log4j.appender.stdout.layout=org.apache.log4j.patternlayout log4j.appender.stdout.layout.conversionpattern=%d{yyyy-mm-dd hh:mm:ss} %-5p %c{1}:%l %% %m%n log4j.appender.kafka=kafka.producer.kafkalog4jappender log4j.appender.kafka.brokerlist=localhost:9092 log4j.appender.kafka.topic=kfklogs log4j.appender.kafka.serializerclass=kafka.producer.defaultstringencoder log4j.appender.kafka.layout=org.apache.log4j.patternlayout log4j.appender.kafka.layout.conversionpattern=%d{yyyy-mm-dd hh:mm:ss} %-5p %c{1}:%l %% - %m%n log4j.logger.loggen=debug, kafka
however, not able receive messages in consumer. have tested consumer other producer code , works fine.
also, warning
log4j:warn no such property [serializerclass] in kafka.producer.kafkalog4jappender.
edit
and here code generates log messages
package loggen; import org.apache.log4j.logger; public class testlog4j { static logger log = logger.getlogger(testlog4j.class.getname()); public static void main(string[] args) { log.debug("debug message"); log.info("info message"); log.error("error message"); log.fatal("fatal message"); log.warn("warn message"); log.trace("trace message"); } }
also, if write log messages file using like
log4j.appender.kafka=org.apache.log4j.dailyrollingfileappender log4j.appender.kafka.datepattern='.'yyyy-mm-dd-hh log4j.appender.kafka.file=logs/server.log
i can see log messages in server.log file
thanks suggestions everyone. think weird behavior see might related kafka set up. here contents of server.properties file use start kafka server. can see odd ?
broker.id=0 port=9092 num.network.threads=3 num.io.threads=8 socket.send.buffer.bytes=102400 socket.receive.buffer.bytes=102400 socket.request.max.bytes=104857600 log.dirs=/users/xyz/kafka/kafka-logs num.partitions=1 num.recovery.threads.per.data.dir=1 log.retention.hours=168 log.segment.bytes=1073741824 log.retention.check.interval.ms=300000 log.cleaner.enable=false zookeeper.connect=localhost:2181 zookeeper.connection.timeout.ms=6000 delete.topic.enable=true
i have took @ source code of kafkalog4jappender.scala , here valid , exhaustive properties kafka log4j appender of version 0.8.2.1 : topic, brokerlist, compressiontype, requirednumacks, syncsend.
the log4j.properties worked me below :
log4j.rootlogger=error, stdout log4j.logger.loggen=debug, kafka log4j.appender.stdout=org.apache.log4j.consoleappender log4j.appender.stdout.layout=org.apache.log4j.patternlayout log4j.appender.stdout.layout.conversionpattern=%d{yyyy-mm-dd hh:mm:ss} %-5p %c{1}:%l %% %m%n log4j.appender.kafka=kafka.producer.kafkalog4jappender log4j.appender.kafka.topic=log log4j.appender.kafka.brokerlist=localhost:9092 log4j.appender.kafka.compressiontype=none log4j.appender.kafka.requirednumacks=0 log4j.appender.kafka.syncsend=true log4j.appender.kafka.layout=org.apache.log4j.patternlayout log4j.appender.kafka.layout.conversionpattern=%d{yyyy-mm-dd hh:mm:ss} %-5p %c{1}:%l %% - %m%n
Comments
Post a Comment