<> Cause analysis
Many programmers may accidentally log like this
logger.error(e); logger.error(e.getMessage); logger.error(" error message :" + e);
look down logger.error You know the code error yes 2 Overloaded methods
public void error(String msg); public void error(String msg, Throwable t);
The above code has only one parameter , Therefore, it is considered to call the first method , The result is that e Will be automatically converted to String type , So many error messages are lost , Stack information .
<> Error examples
The following stack information is basically lost , I don't know which method is called service Errors caused , I don't know the cause of the mistake , We don't know how many lines the code throws an exception . In case of production problems , There's no way to start , I can't turn on the computer debug bar ? It's like a doctor asking a patient what's wrong , The patient was not feeling well , If I were a doctor, I would want to hit someone on the spot
logger.error(" The third x Partial error " + e); 05:10:05.920 [startQuartz_Worker-8] ERROR com.cmx.
demo.data.outter.TestService - The third 1 Partial error
<> Correct example
And the right log , We can know the cause of the error , The number of rows that threw the exception , At the same time, we can know the relationship between stack calls , Only in this way can the production problems be solved . The doctor still asked the patient what was wrong , The patient answered me because of so and so , It causes low back pain on the left side , That's a lot clearer
logger.error(" The third x Partial error ", e); 05:10:05.920 [startQuartz_Worker-8] ERROR com.cmx.
demo.data.outter.TestService - Current file name :DMDXXX.csv The third x Partial error com.cmx.common.exception.
AppException: The third x Partial error at com.cmx.demo.data.outter.TestService.execAnalyze(
TestService.java:169) ~[TestService.class:?] at com.cmx.demo.data.outter.
TestService.execAnalyze(TestService.java:81) [TestService.class:?] at com.cmx.
demo.data.outter.TestService$$FastClassBySpringCGLIB$$4538247f.invoke(<generated
>) [TestService.class:?] at org.springframework.cglib.proxy.MethodProxy.invoke(
MethodProxy.java:204) [spring-core-4.3.24.RELEASE.jar:4.3.24.RELEASE] at org.
springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.
invokeJoinpoint(CglibAopProxy.java:736) [spring-aop-4.3.24.RELEASE.jar:4.3.24.
RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed
(ReflectiveMethodInvocation.java:157) [spring-aop-4.3.24.RELEASE.jar:4.3.24.
RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor$
1.proceedWithInvocation(TransactionInterceptor.java:99) [spring-tx-4.3.24.
RELEASE.jar:4.3.24.RELEASE] at org.springframework.transaction.interceptor.
TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:
283) [spring-tx-4.3.24.RELEASE.jar:4.3.24.RELEASE] at org.springframework.
transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.
java:96) [spring-tx-4.3.24.RELEASE.jar:4.3.24.RELEASE] at org.springframework.
aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java
:179) [spring-aop-4.3.24.RELEASE.jar:4.3.24.RELEASE] at org.springframework.aop.
framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:
671) [spring-aop-4.3.24.RELEASE.jar:4.3.24.RELEASE] at com.cmx.demo.data.outter.
TestService$$EnhancerBySpringCGLIB$$24bd9037.execAnalyze(<generated>) [
TestService.class:?] at com.cmx.demo.data.outter.job.CyberAnalyzeJob.invoke(
CyberAnalyzeJob.java:29) [CyberAnalyzeJob.class:?] at com.cmx.common.job.BaseJob
.execJob(BaseJob.java:57) [BaseJob.class:?] at sun.reflect.
GeneratedMethodAccessor142.invoke(Unknown Source) ~[?:?] at sun.reflect.
DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:
1.8.0_60] at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_60] at
org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:265) [spring-
core-4.3.24.RELEASE.jar:4.3.24.RELEASE] at org.springframework.scheduling.quartz
.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(
MethodInvokingJobDetailFactoryBean.java:257) [spring-context-support-4.3.24.
RELEASE.jar:4.3.24.RELEASE] at org.springframework.scheduling.quartz.
QuartzJobBean.execute(QuartzJobBean.java:75) [spring-context-support-4.3.24.
RELEASE.jar:4.3.24.RELEASE] at org.quartz.core.JobRunShell.run(JobRunShell.java:
202) [quartz-2.2.3.jar:?] at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(
SimpleThreadPool.java:573) [quartz-2.2.3.jar:?] Caused by: java.io.
FileNotFoundException: File D:\xxx\DMDXXX.csv does not exist. at com.csvreader.
CsvReader.<init>(Unknown Source) ~[javacsv.jar:?] at com.cmx.demo.data.outter.
TestService.execAnalyze(TestService.java:157) ~[TestService.class:?] ... 21 more
Technology
Daily Recommendation