line/armeria

Add `KafkaLogWriter`

Open

#4,958 opened on Jun 15, 2023

View on GitHub
 (5 comments) (0 reactions) (0 assignees)Java (4,552 stars) (863 forks)batch import
good first issuenew feature

Description

The default LogWriter uses SLFJ4 to write serialized RequestLogs. In the cloud environment, it would be better to send logs to the remote message queue directly rather than write logs to the local filesystem.

Like KafkaAccessLogWriter, KafkaLogWriter can be added to the armeria-kafka module. https://github.com/line/armeria/blob/d8a744b467271efb4a617584f5d70d8ac140f7f5/kafka/src/main/java/com/linecorp/armeria/server/logging/kafka/KafkaAccessLogWriter.java#L41-L41

public final class KafkaLogWriter implements LogWriter {
    @Override
    public void logRequest(RequestOnlyLog log) {
        // use LogFormatter.ofJson() to convert the log to a JSON object
    }

    @Override
    public void logResponse(RequestLog log) {
        ...
    }
}

Contributor guide

Add `KafkaLogWriter` · line/armeria#4958 | Good First Issue