Skip to content

Commit

Permalink
[INLONG-11455][Sort] Append the install/uninstall logs by the specifi…
Browse files Browse the repository at this point in the history
…ed log level
  • Loading branch information
qy-liuhuo committed Nov 10, 2024
1 parent 8af51b9 commit c937edc
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.core.layout.PatternLayout;
import org.apache.logging.log4j.message.SimpleMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -209,7 +211,11 @@ public boolean install() {
createOpenTelemetrySdk();
// install OpenTelemetryAppender
OpenTelemetryAppender.install(SDK);
LOG.info("OpenTelemetryLogger installed");
otelAppender.append(
new Log4jLogEvent.Builder()
.setLevel(this.logLevel)
.setMessage(new SimpleMessage("OpenTelemetryLogger installed"))
.build());
return true;
}
}
Expand All @@ -232,7 +238,11 @@ public boolean uninstall() {
Configuration config = loggerContext.getConfiguration();
config.getAppenders().values().forEach(appender -> {
if (appender instanceof OpenTelemetryAppender) {
LOG.info("Uninstall OpenTelemetryLogger");
appender.append(
new Log4jLogEvent.Builder()
.setLevel(this.logLevel)
.setMessage(new SimpleMessage("OpenTelemetryLogger uninstalled"))
.build());
config.getRootLogger().removeAppender(appender.getName());
appender.stop();
}
Expand Down

0 comments on commit c937edc

Please sign in to comment.