| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -9,19 +9,18 @@ import ch.qos.logback.core.spi.FilterReply; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.constant.ThreadLocalConstant; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.dto.form.DingTalkTextMsg; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.enums.EnvEnum; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.utils.DateUtils; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.utils.DingdingMsgSender; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import com.epmet.commons.tools.utils.SpringContextUtils; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.apache.commons.lang3.StringUtils; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.slf4j.Logger; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.slf4j.LoggerFactory; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.springframework.cloud.commons.util.InetUtils; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.springframework.core.env.Environment; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.springframework.web.context.request.RequestAttributes; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.springframework.web.context.request.RequestContextHolder; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.springframework.web.context.request.ServletRequestAttributes; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import javax.servlet.http.HttpServletRequest; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import java.text.SimpleDateFormat; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import java.util.regex.Matcher; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import java.util.regex.Pattern; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -47,40 +46,42 @@ public class LogMsgSendFilter extends LevelFilter { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        //如果日志级别等于设置的日志级别 则发送消息
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (event.getLevel().isGreaterOrEqual(Level.ERROR)) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            try { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                getServerInfo(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                StringBuilder stringBuilder = new StringBuilder(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                stringBuilder.append("【日志告警】\n"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                stringBuilder.append("\n"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                stringBuilder.append("告警级别:" + event.getLevel()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                stringBuilder.append("告警级别:").append(event.getLevel()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                stringBuilder.append("\n"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if (StringUtils.isNotBlank(appName)) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    stringBuilder.append("服务名称:" + appName); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    stringBuilder.append("服务名称:").append(appName); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    stringBuilder.append("\n"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                getServerInfo(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if (StringUtils.isNotBlank(activeEnv)) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    stringBuilder.append("告警环境:" + EnvEnum.getEnum(activeEnv).getName()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    stringBuilder.append("告警环境:").append(activeEnv); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    stringBuilder.append("\n"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if (StringUtils.isNotBlank(serverIp)) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    stringBuilder.append("IP地址:" + serverIp); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    stringBuilder.append("IP地址:").append(serverIp); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    stringBuilder.append("\n"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                stringBuilder.append("故障时间:" + formatLongTime2Str(event.getTimeStamp())); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                stringBuilder.append("故障时间:").append(DateUtils.formatTimestamp(event.getTimeStamp(),DateUtils.DATE_TIME_PATTERN)); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                stringBuilder.append("\n"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                stringBuilder.append("TraceId:" + Thread.currentThread().getName()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                stringBuilder.append("TraceId:").append(Thread.currentThread().getName()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                stringBuilder.append("\n"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                HttpServletRequest request = getRequest(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if (request != null) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    String requestURI = request.getRequestURI(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    stringBuilder.append("请求路径:" + requestURI); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    stringBuilder.append("请求路径:").append(requestURI); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    stringBuilder.append("\n"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    stringBuilder.append("请求参数:" + ThreadLocalConstant.requestParam.get()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    stringBuilder.append("请求参数:").append(ThreadLocalConstant.requestParam.get()); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    stringBuilder.append("\n"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -89,7 +90,7 @@ public class LogMsgSendFilter extends LevelFilter { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if (throwableProxy == null && formattedMessage.length() > 1000) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    formattedMessage = formattedMessage.substring(0, getCharacterPosition(formattedMessage, baseProjectPackage, 5)); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                stringBuilder.append("告警信息:" + formattedMessage); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                stringBuilder.append("告警信息:").append(formattedMessage); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                stringBuilder.append("\n"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -134,12 +135,8 @@ public class LogMsgSendFilter extends LevelFilter { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        try { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if (activeEnv == null) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                Environment environment = SpringContextUtils.getBean(Environment.class); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                String[] activeProfiles = environment.getActiveProfiles(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                if (activeProfiles != null && activeProfiles.length > 0) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    logger.info("activeProfiles:{}", activeProfiles); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                    activeEnv = activeProfiles[0]; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                EnvEnum currentEnv = EnvEnum.getCurrentEnv(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                activeEnv = currentEnv.getName(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } catch (Exception e) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            logger.warn("getServerInfo get bean Environment exception", e); | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -212,16 +209,6 @@ public class LogMsgSendFilter extends LevelFilter { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    private String formatLongTime2Str(long timestamp) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        return dateFormat.format(timestamp); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public void setActiveEnv(String activeEnv) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        this.activeEnv = activeEnv; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public void setAppName(String appName) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        this.appName = appName; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |