{"record":{"id":"54195587859e3c0a","repo":"zhisheng17/flink-learning","slug":"topic-must-be-specified-by-the-kafka-log4j-appende","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/Log4j2KafkaAppender/src/main/java/com/zhisheng/log/appender/KafkaLog4j2Appender.java","lineNumber":110,"sourceCode":"                log.error(\"log.file Property ({}) doesn't contains yarn application id or container id\", logFile);\n            }\n        }\n\n        taskName = envProperties.getProperty(\"taskName\", null);\n        taskId = envProperties.getProperty(\"taskId\", null);\n\n        Properties props = new Properties();\n        for (Property property : properties) {\n            props.put(property.getName(), property.getValue());\n        }\n\n        if (bootstrapServers != null) {\n            props.setProperty(\"bootstrap.servers\", 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\n        String clientIdPrefix = taskId != null ? taskId : appId;\n\n        if (clientIdPrefix != null) {\n            props.setProperty(\"client.id\", clientIdPrefix + \"_log\");\n        }\n\n        if (props.getProperty(\"acks\") == null) {\n            props.setProperty(\"acks\", \"0\");\n        }\n\n        if (props.getProperty(\"retries\") == null) {\n            props.setProperty(\"retries\", \"0\");\n        }\n\n        if (props.getProperty(\"batch.size\") == null) {\n            props.setProperty(\"batch.size\", \"16384\");","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/zhisheng17/flink-learning/blob/d731cee7618021be56d132cc925102ffff8d75e6/flink-learning-extends/FlinkLogKafkaAppender/Log4j2KafkaAppender/src/main/java/com/zhisheng/log/appender/KafkaLog4j2Appender.java#L92-L128","documentation":"KafkaLog4j2Appender requires a target Kafka topic to which log events are produced. If the topic attribute is null after configuration parsing, it throws ConfigException during appender initialization.","triggerScenarios":"Configuring <KafkaLog4j2Appender bootstrapServers=\"...\"> without the topic attribute in log4j2.xml.","commonSituations":"Forgotten topic attribute; topic supplied under a wrong attribute name; XML config assembled programmatically omitting the field.","solutions":["Add topic=\"your-topic\" to the <KafkaLog4j2Appender> element.","Ensure the topic already exists in Kafka or enable auto topic creation on the broker.","Double-check attribute casing/typos in log4j2.xml.","Verify with a smoke log that events are delivered to the topic."],"exampleFix":"// before\n<KafkaLog4j2Appender bootstrapServers=\"broker:9092\"/>\n// after\n<KafkaLog4j2Appender bootstrapServers=\"broker:9092\" topic=\"app-logs\"/>","handlingStrategy":"validation","validationCode":"if (topic == null || topic.isEmpty())\n    throw new IllegalStateException(\"KafkaLog4j2Appender topic attribute is required\");","typeGuard":null,"tryCatchPattern":"try {\n    LOGGER.info(\"startup\");\n} catch (Throwable t) {\n    System.err.println(\"Kafka appender misconfigured: \" + t.getMessage());\n}","preventionTips":["Include topic in every KafkaLog4j2Appender declaration","Create topics ahead of deployment (or enable broker auto-create)","Verify attribute names against the appender's @PluginAttr definitions","Add a config lint step that parses log4j2.xml and checks required attributes"],"tags":["kafka","logging","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-14T00:17:10.932Z"}