我想在cloudera集群中将kafka appender添加到audithdfs日志中。
我已经成功地配置了带有kafka appender的log4j2.xml文件,我需要将这个log4j2.xml转换成log4j2.properties文件,以便能够将它与hdfs log log4j2.properties文件合并。我不能这样做,因为当我用log4j2.properties而不是xml启动虚拟进程时,我得到了一个错误。
我尝试过用几种不同的方法编写属性文件,结果总是导致bootstrap.servers属性出现问题
这是我的属性文件
filters = threshold
filter.threshold.type = ThresholdFilter
filter.threshold.level = ALL
appenders = console,kafka
appender.console.type = Console
appender.console.name = console
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %m%n
appender.kafka.type = Kafka
appender.kafka.name = kafka
appender.kafka.layout.type = PatternLayout
appender.kafka.layout.pattern =%m%n
appender.kafka.property.type = Property
appender.kafka.property.bootstrap.servers = ip:port
appender.kafka.topic = cdh-audit-hdfs
问题出在这行:appender.kafka.property.bootstrap.servers=ip:port
我试过以下方法,但没有效果:
appender.kafka.property.bootstrap.servers = ip:port
appender.kafka.property.bootstrap\.servers = ip:port
appender.kafka.property.name = "bootstrap.servers"
appender.kafka.property.bootstrap.servers = ip:port
appender.kafka.property.key = "bootstrap.servers"
appender.kafka.property.value = ip:port
等。。。
这是我的虚拟过程:
package blabla
import org.apache.logging.log4j.LogManager
object dummy extends App{
val logger = LogManager.getLogger
val record = "...c"
while(true){
logger.info(record)
Thread.sleep(5000)
}
}
我需要如何配置log4j2.properties才能定义这个属性?
我希望这个过程在我的Kafka主题中写下记录,但是我却得到了如下错误:
Exception in thread "main" org.apache.logging.log4j.core.config.ConfigurationException: No type attribute provided for component bootstrap
Exception in thread "main" org.apache.kafka.common.config.ConfigException: Missing required configuration "bootstrap.servers" which has no default value.
1条答案
按热度按时间evrscar21#
试试这个解决方案,它对我有用: