-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement](fe exception) write a java annotation to catch throwable from a method and print log #17797
[Enhancement](fe exception) write a java annotation to catch throwable from a method and print log #17797
Conversation
…on_log_annotation' into kongxuan.yao/Feature/add_exception_log_annotation
Could you please describe:
|
|
||
@AfterThrowing(value = "throwingLogPointCut()", throwing = "e") | ||
public void exceptionLog(Exception e) { | ||
LOG.error(e.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Print 2 logs in one line.
And do we need to print stack trace for each exception? Maybe we can use a flag to control it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a parameter to let the user decide whether to print the stack information, the default is not to print
|
TeamCity pipeline, clickbench performance test result: |
ExceptionLog exceptionLog = method.getAnnotation(ExceptionLog.class); | ||
LOG.warn(e.getMessage()); | ||
if (exceptionLog != null && exceptionLog.isGetStackTrace()) { | ||
LOG.warn(getStackTrace(e)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOG.warn(e) will print stack trace automatically.
@@ -181,6 +182,7 @@ public Set<String> getTableNamesForShow() { | |||
.collect(Collectors.toSet()); | |||
} | |||
|
|||
@ExceptionLog |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using @LogException instead.
} | ||
|
||
@AfterThrowing(value = "throwingLogPointCut()", throwing = "e") | ||
public void exceptionLog(JoinPoint point, Exception e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using Throwable intead of Exception, Exception is only subset of errors.
import java.lang.reflect.Method; | ||
|
||
@Aspect | ||
public class LogAspect { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add another annotation.
@NoException
If a method throws any exceptions, should print log and call system.exit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR approved by at least one committer and no changes requested. |
PR approved by anyone and no changes requested. |
run buildall |
it does not work on mac, or newer version of JDK |
In #17797 , we introduced aspectj to help log exception easily. However, the plugin version 1.11 do not support jdk9 and later. For support compile FE with jdk11 update aspectj-maven-plugin to 1.14.0 version add new dependency org.aspectj.aspectjrt 1.9.7 to fe-core according to: aspectj java version compatibility aspectj-maven-plugin issue aspectj release note intro to aspectj
…e from a method and print log (apache#17797) How it works? Aspectj is used to implement the aspect function of annotations. During the compilation process, the aspectj-maven-plugin plugin will automatically weave the code with aspect annotations into the generated classes file. When to use to? When a method wants to add a try catch to save exception information, the LogException annotation can be used. When there is a method that does not allow errors, the NoException annotation can be used. What is the result when adding this annotation? Use the LogException annotation to automatically capture exceptions into the Log file, and the code can be more concise. Use the NoException annotation to automatically capture the exception to the Log file and exit the program when an exception occurs.
In apache#17797 , we introduced aspectj to help log exception easily. However, the plugin version 1.11 do not support jdk9 and later. For support compile FE with jdk11 update aspectj-maven-plugin to 1.14.0 version add new dependency org.aspectj.aspectjrt 1.9.7 to fe-core according to: aspectj java version compatibility aspectj-maven-plugin issue aspectj release note intro to aspectj
Proposed changes
Issue Number: close #17238
Problem summary
Aspectj is used to implement the aspect function of annotations. During the compilation process, the aspectj-maven-plugin plugin will automatically weave the code with aspect annotations into the generated classes file.
When a method wants to add a try catch to save exception information, the LogException annotation can be used. When there is a method that does not allow errors, the NoException annotation can be used.
Use the LogException annotation to automatically capture exceptions into the Log file, and the code can be more concise. Use the NoException annotation to automatically capture the exception to the Log file and exit the program when an exception occurs.
Checklist(Required)
Further comments
If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...