Skip to content

Commit

Permalink
add instance and fqn into log message properties (#11399)
Browse files Browse the repository at this point in the history
### Motivation

Enrich the published log message with `instanceId` and `fqn` set in properties.

### Modifications

add `instanceId` and `fqn` into log message properties

(cherry picked from commit b6d02e4)
  • Loading branch information
nlu90 authored and codelipenghui committed Jul 30, 2021
1 parent cb7e29f commit 5397edc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Expand Up @@ -574,7 +574,8 @@ private void setupLogHandler() {
// to prevent "SSE4.2 CRC32C provider initialized" appearing in log topic
new Crc32cIntChecksum();
logAppender = new LogAppender(client, instanceConfig.getFunctionDetails().getLogTopic(),
FunctionCommon.getFullyQualifiedName(instanceConfig.getFunctionDetails()));
FunctionCommon.getFullyQualifiedName(instanceConfig.getFunctionDetails()),
instanceConfig.getInstanceName());
logAppender.start();
setupLogTopicAppender(LoggerContext.getContext());
}
Expand Down
Expand Up @@ -35,21 +35,25 @@ public class LogAppender implements Appender {
private PulsarClient pulsarClient;
private String logTopic;
private String fqn;
private String instance;
private State state;
private ErrorHandler errorHandler;
private Producer<byte[]> producer;

public LogAppender(PulsarClient pulsarClient, String logTopic, String fqn) {
public LogAppender(PulsarClient pulsarClient, String logTopic, String fqn, String instance) {
this.pulsarClient = pulsarClient;
this.logTopic = logTopic;
this.fqn = fqn;
this.instance = instance;
}

@Override
public void append(LogEvent logEvent) {
producer.newMessage()
.value(logEvent.getMessage().getFormattedMessage().getBytes(StandardCharsets.UTF_8))
.property("loglevel", logEvent.getLevel().name())
.property("instance", instance)
.property("fqn", fqn)
.sendAsync();
}

Expand Down

0 comments on commit 5397edc

Please sign in to comment.