美文网首页
SingleThreadWrapper

SingleThreadWrapper

作者: CentForever | 来源:发表于2021-10-09 20:47 被阅读0次

    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;
        }
    }
    

    相关文章

      网友评论

          本文标题:SingleThreadWrapper

          本文链接:https://www.haomeiwen.com/subject/fonhhltx.html