https://github.com/fff/feign-fluentd-logger/blob/5eda829ce5a00f6314f409ad99c020014ce5b6f2/src/main/java/feign/fluentd/SingleThreadWrapper.java
import org.fluentd.logger.FluentLogger;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public final class SingleThreadWrapper extends FluentLogger {
private final ExecutorService executorService;
private final FluentLogger realLogger;
public SingleThreadWrapper(FluentLogger realLogger) {
this.executorService = Executors.newSingleThreadExecutor();
this.realLogger = realLogger;
}
@Override
public boolean log(String tag, String key, Object value) {
return super.log(tag, key, value);
}
@Override
public boolean log(String tag, String key, Object value, long timestamp) {
return super.log(tag, key, value, timestamp);
}
@Override
public boolean log(String tag, Map<String, Object> data) {
return super.log(tag, data);
}
@Override
public boolean log(String tag, Map<String, Object> data, long timestamp) {
this.executorService.submit(() -> {
try {
realLogger.log(tag, data, timestamp);
} catch (Exception e) {
e.printStackTrace();
}
});
return true;
}
}
网友评论