Skip to content
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

应用日志优化建议 #238

Open
HolidayLee opened this issue Feb 24, 2021 · 0 comments
Open

应用日志优化建议 #238

HolidayLee opened this issue Feb 24, 2021 · 0 comments

Comments

@HolidayLee
Copy link

由于项目采取大量的异步线程池执行,所以说一个流程的日志散落到了多行,线上出现异常的时候不好定位问题,建议给每个流程添加一个追踪id,用于在出现异常时能很快把相关日志全部查出,暂时看到了三个切入点:
1.http请求可添加一个全局的/**的拦截器
MDC.put("TansId", TransIdUtils.generateDateTimeInnerTransId());
2.异步线程池mdc跟踪,KeyCallable中添加变量mdc上下文内容
private final Map<String, String> logContextMap;
logContextMap = MDC.getCopyOfContextMap();
if (this.logContextMap != null) { MDC.setContextMap(this.logContextMap); }
3.quartz定时任务,CacheBaseJob的excute函数中添加追踪id
MDC.put("TansId", TransIdUtils.generateDateTimeInnerTransId());
4.应用日志异步打印,实时刷盘会局限于磁盘io性能
5.日志格式、存放路径之类的可配置化

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant