|
@ -6,6 +6,7 @@ import ch.qos.logback.classic.spi.ILoggingEvent; |
|
|
import ch.qos.logback.classic.spi.IThrowableProxy; |
|
|
import ch.qos.logback.classic.spi.IThrowableProxy; |
|
|
import ch.qos.logback.classic.spi.StackTraceElementProxy; |
|
|
import ch.qos.logback.classic.spi.StackTraceElementProxy; |
|
|
import ch.qos.logback.core.spi.FilterReply; |
|
|
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.dto.form.DingTalkTextMsg; |
|
|
import com.epmet.commons.tools.enums.EnvEnum; |
|
|
import com.epmet.commons.tools.enums.EnvEnum; |
|
|
import com.epmet.commons.tools.utils.DingdingMsgSender; |
|
|
import com.epmet.commons.tools.utils.DingdingMsgSender; |
|
@ -15,9 +16,12 @@ import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.springframework.cloud.commons.util.InetUtils; |
|
|
import org.springframework.cloud.commons.util.InetUtils; |
|
|
import org.springframework.core.env.Environment; |
|
|
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.text.SimpleDateFormat; |
|
|
import java.util.Arrays; |
|
|
|
|
|
import java.util.regex.Matcher; |
|
|
import java.util.regex.Matcher; |
|
|
import java.util.regex.Pattern; |
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
@ -64,14 +68,26 @@ public class LogMsgSendFilter extends LevelFilter { |
|
|
stringBuilder.append("IP地址:" + serverIp); |
|
|
stringBuilder.append("IP地址:" + serverIp); |
|
|
stringBuilder.append("\n"); |
|
|
stringBuilder.append("\n"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
stringBuilder.append("故障时间:" + formatLongTime2Str(event.getTimeStamp())); |
|
|
stringBuilder.append("故障时间:" + formatLongTime2Str(event.getTimeStamp())); |
|
|
stringBuilder.append("\n"); |
|
|
stringBuilder.append("\n"); |
|
|
stringBuilder.append("TraceId:" + Thread.currentThread().getName()); |
|
|
stringBuilder.append("TraceId:" + Thread.currentThread().getName()); |
|
|
stringBuilder.append("\n"); |
|
|
stringBuilder.append("\n"); |
|
|
|
|
|
|
|
|
|
|
|
HttpServletRequest request = getRequest(); |
|
|
|
|
|
if (request != null) { |
|
|
|
|
|
String requestURI = request.getRequestURI(); |
|
|
|
|
|
stringBuilder.append("请求路径:" + requestURI); |
|
|
|
|
|
stringBuilder.append("\n"); |
|
|
|
|
|
|
|
|
|
|
|
stringBuilder.append("请求参数:" + ThreadLocalConstant.requestParam.get()); |
|
|
|
|
|
stringBuilder.append("\n"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
String formattedMessage = event.getFormattedMessage(); |
|
|
String formattedMessage = event.getFormattedMessage(); |
|
|
IThrowableProxy throwableProxy = event.getThrowableProxy(); |
|
|
IThrowableProxy throwableProxy = event.getThrowableProxy(); |
|
|
if (throwableProxy == null && formattedMessage.length() > 1000) { |
|
|
if (throwableProxy == null && formattedMessage.length() > 1000) { |
|
|
formattedMessage = formattedMessage.substring(0, getCharacterPosition(formattedMessage, baseProjectPackage, 5)); |
|
|
formattedMessage = formattedMessage.substring(0, getCharacterPosition(formattedMessage, baseProjectPackage, 5)); |
|
|
} |
|
|
} |
|
|
stringBuilder.append("告警信息:" + formattedMessage); |
|
|
stringBuilder.append("告警信息:" + formattedMessage); |
|
|
stringBuilder.append("\n"); |
|
|
stringBuilder.append("\n"); |
|
@ -159,105 +175,19 @@ public class LogMsgSendFilter extends LevelFilter { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
/** |
|
|
String msg = "<<<<<<<<异常响应<<<<<<<<:事务流水号:na1597027822634, 执行时长:59ms, 响应数据:{\"code\":8102,\"internalMsg\":\"验证码错误\",\"msg\":\"验证码错误\"}, 异常信息:验证码错误, 堆栈信息:com.epmet.commons.tools.exception.RenException: \n" + |
|
|
* 获取Request对象 |
|
|
" at com.epmet.service.impl.VolunteerInfoServiceImpl.authenticate(VolunteerInfoServiceImpl.java:91)\n" + |
|
|
* |
|
|
" at com.epmet.service.impl.VolunteerInfoServiceImpl$$FastClassBySpringCGLIB$$7babb2e8.invoke(<generated>)\n" + |
|
|
* @return |
|
|
" at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)\n" + |
|
|
*/ |
|
|
" at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:750)\n" + |
|
|
private HttpServletRequest getRequest() { |
|
|
" at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)\n" + |
|
|
RequestAttributes ra = RequestContextHolder.getRequestAttributes(); |
|
|
" at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:295)\n" + |
|
|
ServletRequestAttributes sra = (ServletRequestAttributes) ra; |
|
|
" at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)\n" + |
|
|
if (sra == null){ |
|
|
" at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\n" + |
|
|
return null; |
|
|
" at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)\n" + |
|
|
} |
|
|
" at com.epmet.service.impl.VolunteerInfoServiceImpl$$EnhancerBySpringCGLIB$$f78b4778.authenticate(<generated>)\n" + |
|
|
return sra.getRequest(); |
|
|
" at com.epmet.controller.ResiVolunteerController.authenticate(ResiVolunteerController.java:59)\n" + |
|
|
|
|
|
" at com.epmet.controller.ResiVolunteerController$$FastClassBySpringCGLIB$$e023fb55.invoke(<generated>)\n" + |
|
|
|
|
|
" at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)\n" + |
|
|
|
|
|
" at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:750)\n" + |
|
|
|
|
|
" at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)\n" + |
|
|
|
|
|
" at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56)\n" + |
|
|
|
|
|
" at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\n" + |
|
|
|
|
|
" at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88)\n" + |
|
|
|
|
|
" at com.epmet.commons.tools.aspect.BaseRequestLogAspect.proceed(BaseRequestLogAspect.java:66)\n" + |
|
|
|
|
|
" at com.epmet.aspect.RequestLogAspect.proceed(RequestLogAspect.java:26)\n" + |
|
|
|
|
|
" at sun.reflect.GeneratedMethodAccessor195.invoke(Unknown Source)\n" + |
|
|
|
|
|
" at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n" + |
|
|
|
|
|
" at java.lang.reflect.Method.invoke(Method.java:498)\n" + |
|
|
|
|
|
" at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)\n" + |
|
|
|
|
|
" at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)\n" + |
|
|
|
|
|
" at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)\n" + |
|
|
|
|
|
" at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\n" + |
|
|
|
|
|
" at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)\n" + |
|
|
|
|
|
" at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)\n" + |
|
|
|
|
|
" at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)\n" + |
|
|
|
|
|
" at com.epmet.controller.ResiVolunteerController$$EnhancerBySpringCGLIB$$1c0751c0.authenticate(<generated>)\n" + |
|
|
|
|
|
" at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n" + |
|
|
|
|
|
" at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n" + |
|
|
|
|
|
" at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n" + |
|
|
|
|
|
" at java.lang.reflect.Method.invoke(Method.java:498)\n" + |
|
|
|
|
|
" at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)\n" + |
|
|
|
|
|
" at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)\n" + |
|
|
|
|
|
" at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)\n" + |
|
|
|
|
|
" at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:893)\n" + |
|
|
|
|
|
" at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:798)\n" + |
|
|
|
|
|
" at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)\n" + |
|
|
|
|
|
" at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)\n" + |
|
|
|
|
|
" at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)\n" + |
|
|
|
|
|
" at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)\n" + |
|
|
|
|
|
" at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)\n" + |
|
|
|
|
|
" at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)\n" + |
|
|
|
|
|
" at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)\n" + |
|
|
|
|
|
" at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n" + |
|
|
|
|
|
" at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n" + |
|
|
|
|
|
" at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:88)\n" + |
|
|
|
|
|
" at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n" + |
|
|
|
|
|
" at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)\n" + |
|
|
|
|
|
" at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n" + |
|
|
|
|
|
" at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)\n" + |
|
|
|
|
|
" at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n" + |
|
|
|
|
|
" at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:94)\n" + |
|
|
|
|
|
" at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n" + |
|
|
|
|
|
" at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:114)\n" + |
|
|
|
|
|
" at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:104)\n" + |
|
|
|
|
|
" at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n" + |
|
|
|
|
|
" at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)\n" + |
|
|
|
|
|
" at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)\n" + |
|
|
|
|
|
" at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)\n" + |
|
|
|
|
|
" at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)\n" + |
|
|
|
|
|
" at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)\n" + |
|
|
|
|
|
" at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)\n" + |
|
|
|
|
|
" at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367)\n" + |
|
|
|
|
|
" at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)\n" + |
|
|
|
|
|
" at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860)\n" + |
|
|
|
|
|
" at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1591)\n" + |
|
|
|
|
|
" at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)\n" + |
|
|
|
|
|
" at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\n" + |
|
|
|
|
|
" at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\n" + |
|
|
|
|
|
" at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\n" + |
|
|
|
|
|
" at java.lang.Thread.run(Thread.java:745)"; |
|
|
|
|
|
|
|
|
|
|
|
String substring = msg.substring(0, getCharacterPosition(msg, "com.epme1t", 5)); |
|
|
|
|
|
System.out.println(substring); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|