{"record":{"id":"05e4edfb54544672","repo":"zhisheng17/flink-learning","slug":"topic-must-be-specified-by-the-kafka-log4j-appende-05e4ed","errorCode":null,"errorMessage":"Topic must be specified by the Kafka log4j appender","messagePattern":"Topic must be specified by the Kafka log4j appender","errorType":"validation","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"flink-learning-extends/FlinkLogKafkaAppender/Log4jKafkaAppender/src/main/java/com/zhisheng/log/appender/KafkaLog4jAppender.java","lineNumber":95,"sourceCode":"                containerType = \"taskmanager\";\n            } else {\n                containerType = \"others\";\n            }\n        } else {\n            log.error(\"log.file Property ({}) doesn't contains yarn application id or container id\", logFile);\n        }\n\n        taskId = envProperties.getProperty(\"taskId\", null);\n        taskName = envProperties.getProperty(\"taskName\", null);\n\n        Properties props = new Properties();\n        if (this.bootstrapServers != null) {\n            props.setProperty(\"bootstrap.servers\", this.bootstrapServers);\n        } else {\n            throw new ConfigException(\"The bootstrap servers property must be specified\");\n        }\n        if (this.topic == null) {\n            throw new ConfigException(\"Topic must be specified by the Kafka log4j appender\");\n        }\n        if (this.source == null) {\n            throw new ConfigException(\"Source must be specified by the Kafka log4j appender\");\n        }\n\n        String clientIdPrefix = taskId != null ? taskId : appId;\n\n        if (clientIdPrefix != null) {\n            props.setProperty(\"client.id\", clientIdPrefix + \"_log\");\n        }\n\n        if (this.acks != null) {\n            props.setProperty(\"acks\", this.acks);\n        } else {\n            props.setProperty(\"acks\", \"0\");\n        }\n\n        if (this.retries != null) {","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/zhisheng17/flink-learning/blob/d731cee7618021be56d132cc925102ffff8d75e6/flink-learning-extends/FlinkLogKafkaAppender/Log4jKafkaAppender/src/main/java/com/zhisheng/log/appender/KafkaLog4jAppender.java#L77-L113","documentation":"Thrown as an org.apache.kafka.common.config.ConfigException from KafkaLog4jAppender.activateOptions() when the log4j configuration for this appender lacks the `topic` property (this.topic == null). activateOptions runs once at appender initialization when log4j parses log4j.properties/log4j.xml, so a missing Topic line in the appender config aborts appender startup and the appender cannot deliver any log events to Kafka. The guard is a plain null validation of a user-supplied config key — the at-fault input is the appender's `topic` config property being absent (or empty/unset) in the log4j configuration file.","triggerScenarios":"Appender configured in log4j.properties with BootstrapServers but no Topic option, at logger initialization time.","commonSituations":"Forgotten Topic line; copy-pasted appender config stripped of the Topic; topic set on the wrong appender prefix (e.g. wrong appender name in the key).","solutions":["Add log4j.appender.<name>.Topic=your-topic to log4j.properties.","Make sure the prefix matches the appender name you actually registered.","Create the topic on the broker if it does not exist (or rely on auto-create).","Restart the app so activateOptions() re-runs with valid config."],"exampleFix":"// before\nlog4j.appender.kafka.BootstrapServers=broker:9092\n// after\nlog4j.appender.kafka.BootstrapServers=broker:9092\nlog4j.appender.kafka.Topic=app-logs","handlingStrategy":"validation","validationCode":"java.util.Properties p = new java.util.Properties();\np.load(new FileInputStream(\"log4j.properties\"));\nif (p.getProperty(\"log4j.appender.kafka.Topic\") == null)\n    throw new IllegalStateException(\"Topic missing for KafkaLog4jAppender\");","typeGuard":null,"tryCatchPattern":"try {\n    PropertyConfigurator.configure(\"log4j.properties\");\n} catch (Throwable t) {\n    System.err.println(\"Kafka appender missing Topic: \" + t.getMessage());\n}","preventionTips":["Always set Topic alongside BootstrapServers in the appender config","Ensure the properties key prefix matches the registered appender name","Verify topic existence on the broker before rollout","Keep a checked-in reference log4j.properties with all required keys"],"tags":["kafka","log4j","config"],"backgroundTag":"missing-required-config","analyzedSha":"d731cee7618021be56d132cc925102ffff8d75e6","analyzedAt":"2026-09-06T05:35:08.496Z","contentChangedAt":"2026-09-06T05:35:08.496Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}