sohutv / cachecloud

搜狐视频(sohu tv)Redis私有云平台 :支持Redis多种架构(Standalone、Sentinel、Cluster)高效管理、有效降低大规模redis运维成本,提升资源管控能力和利用率。平台提供快速搭建/迁移,运维管理,弹性伸缩,统计监控,客户端整合接入等功能。(CacheCloud is a Redis cloud management platform. It supports Standalone, Sentinel, and Cluster architectures for Redis, effectively reducing large-scale Redis operation and maintenance costs, and improving resource management and utilization. The platform provides rapid construction/migration, operation and maintenance management, elastic scaling, statistical monitoring, client integration and access and other functions)
http://cachecloud.github.io/
Apache License 2.0
8.78k stars 2.04k forks source link

应用日志优化建议 #238

Open HolidayLee opened 3 years ago

HolidayLee commented 3 years ago

由于项目采取大量的异步线程池执行,所以说一个流程的日志散落到了多行,线上出现异常的时候不好定位问题,建议给每个流程添加一个追踪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.日志格式、存放路径之类的可配置化