会员登录|免费注册|忘记密码|管理入口 返回主站||保存桌面
K linux 部署手机 centos6.5linux手机「K linux 部署手机 centos6.5」
2025-02-16IP属地 湖北4
package com.weds.framework.utils.elk; import java.util.Map; import java.util.concurrent.CompletableFuture; import org.apache.log4j.AppenderSkeleton; import org.apache.log4j.spi.LocationInfo; import org.apache.log4j.spi.LoggingEvent; import com.weds.framework.core.utils.JsonUtil; import com.weds.framework.core.utils.redis.RedisService; public class ApiAppender extends AppenderSkeleton{ private RedisService redisService; private String writeLogKey; @Override public void close() { // TODO Auto-generated method stub } @Override public boolean requiresLayout() { // TODO Auto-generated method stub return false; } @Override protected void append(LoggingEvent event) { LocationInfo locationInfo = event.getLocationInformation(); Map<String,Object> map =(Map<String,Object>)event.getMessage(); map.put("levl", event.getLevel().toString()); writeLogAsync(writeLogKey,map); } public void writeLogAsync(String key,Map<String,Object> map){ CompletableFuture.runAsync(() -> { writeLog(key,map); }); } public void writeLogAsync(String key,String value){ CompletableFuture.runAsync(() -> { writeLog(key,value); }); } public void writeLog(String key,Map<String,Object> map){ String value = JsonUtil.obj2string(map); writeLog(key, value); } public void writeLog(String key, String value) { if(key != null){ redisService =(RedisService)SpringContextUtil.getBean("redisService",RedisService.class); redisService.setList(key, value); } } public RedisService getRedisService() { return redisService; } public void setRedisService(RedisService redisService) { this.redisService = redisService; } public String getWriteLogKey() { return writeLogKey; } public void setWriteLogKey(String writeLogKey) { this.writeLogKey = writeLogKey; } }