First attach the Kafka operation log profile: Log4j.properties
Set the log according to the appropriate requirements.
#日志级别覆盖规则 Priority: All < DEBUG < INFO <warn < ERROR < FATAL <off#1The . Sub-log Log4j.logger overwrites the primary log Log4j.rootlogger, where the log output level is set, threshold sets the Appender log receive level;2. Log4j.logger level below Threshold,appender receive level depends on threshold level;3the Log4j.logger level above the Threshold,appender receive level depends on the log4j.logger level because there is no threshold required log in the output;4. Sub-logger settings, mainly separate from the Rootlogger section print logs are generally used in conjunction with log4j.additivity #log4j.additivity whether to inherit the output source of the parent logger (appender), the default is true # truein stdout, the output of the Kafkaappender will also be output in the Statechangeappender #这里需要单独输出 so setting to False will only be in Statechangeappender output # Log4j.logger later, if there is no appender, the appender# primary log settings set after Log4j.rootlogger are used by default Log4j.rootlogger=ERROR, stdout, kafkaappender# console Appender and Layoutlog4j.appender.stdout=Org.apache.log4j.ConsoleAppenderlog4j.appender.kafkaAppender.Append=trueLog4j.appender.kafkaAppender.Threshold=ERROR log4j.appender.stdout.layout=Org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=[%D]%p%m (%c)%N#kafkaappender's Appender and Layoutlog4j.appender.kafkaAppender=Org.apache.log4j.DailyRollingFileAppenderlog4j.appender.kafkaAppender.DatePattern= '. ' yyyy-mm-dd-HHlog4j.appender.kafkaAppender.File=${kafka.logs.dir}/Server.loglog4j.appender.kafkaAppender.Append=trueLog4j.appender.kafkaAppender.Threshold=ERROR log4j.appender.kafkaAppender.layout=Org.apache.log4j.PatternLayoutlog4j.appender.kafkaAppender.layout.ConversionPattern=[%D]%p%m (%c)%n# Status change log Log4j.logger.state.change.logger=ERROR, StateChangeAppenderlog4j.additivity.state.change.logger=falseLog4j.appender.stateChangeAppender=Org.apache.log4j.DailyRollingFileAppenderlog4j.appender.stateChangeAppender.DatePattern= '. ' yyyy-mm-dd-HHlog4j.appender.stateChangeAppender.File=${kafka.logs.dir}/state-Change.loglog4j.appender.stateChangeAppender.layout=Org.apache.log4j.PatternLayoutlog4j.appender.stateChangeAppender.layout.ConversionPattern=[%D]%p%m (%c)%n# Request Processing Log4j.logger.kafka.request.logger=ERROR, RequestAppenderlog4j.additivity.kafka.request.logger=falseLog4j.logger.kafka.network.Processor=ERROR, RequestAppenderlog4j.additivity.kafka.network.Processor=falseLog4j.logger.kafka.server.KafkaApis=ERROR, RequestAppenderlog4j.additivity.kafka.server.KafkaApis=falselog4j.logger.kafka.network.requestchannel$=ERROR, requestappenderlog4j.additivity.kafka.network.requestchannel$=falseLog4j.appender.requestAppender=Org.apache.log4j.DailyRollingFileAppenderlog4j.appender.requestAppender.DatePattern= '. ' yyyy-mm-dd-HHlog4j.appender.requestAppender.File=${kafka.logs.dir}/kafka-Request.loglog4j.appender.requestAppender.layout=Org.apache.log4j.PatternLayoutlog4j.appender.requestAppender.layout.ConversionPattern=[%D]%p%m (%c)%N#kafka-Logs Cleaning Log4j.logger.kafka.log.LogCleaner=ERROR, CleanerAppenderlog4j.additivity.kafka.log.LogCleaner=falseLog4j.appender.cleanerAppender=Org.apache.log4j.DailyRollingFileAppenderlog4j.appender.cleanerAppender.DatePattern= '. ' yyyy-mm-dd-HHlog4j.appender.cleanerAppender.File=${kafka.logs.dir}/log-Cleaner.loglog4j.appender.cleanerAppender.layout=Org.apache.log4j.PatternLayoutlog4j.appender.cleanerAppender.layout.ConversionPattern=[%D]%p%m (%c)%N#controllerlog4j.logger.kafka.controller=ERROR, ControllerAppenderlog4j.additivity.kafka.controller=falseLog4j.appender.controllerAppender=Org.apache.log4j.DailyRollingFileAppenderlog4j.appender.controllerAppender.DatePattern= '. ' yyyy-mm-dd-HHlog4j.appender.controllerAppender.File=${kafka.logs.dir}/Controller.loglog4j.appender.controllerAppender.layout=Org.apache.log4j.PatternLayoutlog4j.appender.controllerAppender.layout.ConversionPattern=[%D]%p%m (%c)%N#authorizerlog4j.logger.kafka.authorizer.logger=ERROR, AuthorizerAppenderlog4j.additivity.kafka.authorizer.logger=falseLog4j.appender.authorizerAppender=Org.apache.log4j.DailyRollingFileAppenderlog4j.appender.authorizerAppender.DatePattern= '. ' yyyy-mm-dd-HHlog4j.appender.authorizerAppender.File=${kafka.logs.dir}/kafka-Authorizer.loglog4j.appender.authorizerAppender.layout=Org.apache.log4j.PatternLayoutlog4j.appender.authorizerAppender.layout.ConversionPattern=[%D]%p%m (%c)%n#zkclientlog4j.logger.org.i0itec.zkclient.zkclient=Error#zookeeperlog4j.logger.org.apache.zookeeper=Error#kafkalog4j.logger.kafka=Error#org.apache.kafkalog4j.logger.org.apache.kafka=error
Next Kafka print the GC log by default, as follows,
[Email protected] logs]$lsKafka-authorizer.log Kafkaserver-gc.log.3Kafkaserver-gc.log.8Server.log.2018-Ten- A- -Kafka-request.log Kafkaserver-gc.log.4Kafkaserver-gc.log.9Server.log.2018-Ten- A- theKafkaserver-gc.log.0Kafkaserver-gc.log.5Kafkaserver.outkafkaserver-gc.log.1Kafkaserver-gc.log.6Server.logkafkaserver-gc.log.2. Current Kafkaserver-gc.log.7Server.log.2018-Ten- A- -
Production is unnecessary need to shut down, Kafka home bin directory below there is a kafka-run-class.sh script vim edit
Set the parameter kafka_gc_log_opts= "" to a space, and the GC log is no longer printed after restarting KAFKA.
[Email protected] bin]$ vim Kafka-run-class.SHGc_file_suffix='-gc.log'Gc_log_file_name="'if["x$gc_log_enabled"="xtrue"]; ThenGc_log_file_name=$DAEMON _name$gc_file_suffix kafka_gc_log_opts="-XLOGGC: $LOG _dir/$GC _log_file_name-verbose:gc-xx:+printgcdetails-xx:+printgcdatestamps-xx:+ printgctimestamps-xx:+usegclogfilerotation-xx:numberofgclogfiles=10-xx:gclogfilesize=100m"kafka_gc_log_opts= ""fi
Kafka: Kafka Operation Log Settings