# 框架项目介绍
本框架项目为了解决中小型企业级java项目调用流程的性能追踪问题,提供便捷快速的调用流程追踪日志记录,同时可以记录每个调用函数的耗时。
对于采用executorServic开发的多线程程序同样可以进行追踪,能够加快排查线上多线程问题。
固然目前有比如Zipkin,Drapper这些分布式追踪系统,能够全面的追踪分布式系统的调用链路,但是对于中小型的企业项目搭建及维护成本过高。
地址:https://github.com/husthuke/trace4j
# Qucik Start
在使需要开启追踪日志的项目中引用trace4j-core工程。
```
<dependency>
<groupId>com.hooke</groupId>
<artifactId>trace4j-core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
```
为需要进行日志追踪的方法增加如下注解
```
@Trace(processName = "test",startStep = true)
public void doSomeThing1(){
System.out.println("doSomeThing1");
}
```
结合spring aspect机制定义业务aop
```
<!--Aspect的方式实现trace监测-->
<bean id="traceAspect" class="com.hooke.trace.aop.spring.TraceAspect">
</bean>
<aop:config>
<aop:pointcut id="tracePointcutAspect"
expression="execution(* com.hooke.biz..*(..))"/>
<aop:aspect id="traceSpringAspect" ref="traceAspect">
<aop:around
pointcut-ref="tracePointcutAspect"
method="trace"/>
</aop:aspect>
</aop:config>
```
追踪日志格式
```
"threadId:" + 调用线程ID +
" triceId:" + 追踪ID +
" sessionId:" + 会话ID +
" ProcessName:" + 追踪流程名称 +
" ProcessStep:" + 追踪路程步骤 +
" Joinpoint:" + aop连接点信息 +
" argsJson:" + 方法入参信息 +
" returnJson:" + 方法返回信息 +
" cost:"+ 调用耗时 + " ms!"
```
运行结果示例:
```
1579 [main] INFO c.h.trace.aop.spring.TraceAspect - threadId:1 triceId:887c67ff-7681-4fea-8e9f-e7d3838766f9 sessionId:null ProcessName:test ProcessStep:1. Joinpoint:execution(void com.hooke.biz.TraceTest.doSomeThing1()) argsJson: returnJson: cost:882 ms!
1589 [main] INFO c.h.trace.aop.spring.TraceAspect - threadId:1 triceId:887c67ff-7681-4fea-8e9f-e7d3838766f9 sessionId:null ProcessName:test ProcessStep:2. Joinpoint:execution(void com.hooke.biz.TraceTest.doSomeThing1()) argsJson: returnJson: cost:0 ms!
1590 [main] INFO c.h.trace.aop.spring.TraceAspect - threadId:1 triceId:887c67ff-7681-4fea-8e9f-e7d3838766f9 sessionId:null ProcessName:test ProcessStep:3. Joinpoint:execution(void com.hooke.biz.TraceTest.doSomeThing2()) argsJson: returnJson: cost:1 ms!
1603 [main] INFO c.h.trace.aop.spring.TraceAspect - threadId:1 triceId:887c67ff-7681-4fea-8e9f-e7d3838766f9 sessionId:null ProcessName:test ProcessStep:4. Joinpoint:execution(int com.hooke.biz.TraceTest.doSomeThing3(String)) argsJson:"testmethod3" returnJson:0 cost:13 ms!
1764 [Thread-3] INFO c.h.trace.aop.spring.TraceAspect - threadId:14 triceId:887c67ff-7681-4fea-8e9f-e7d3838766f9 sessionId:null ProcessName:test ProcessStep:4.2. Joinpoint:execution(void com.hooke.biz.TraceTest.doSomeThing2()) argsJson: returnJson: cost:1 ms!
1764 [Thread-1] INFO c.h.trace.aop.spring.TraceAspect - threadId:12 triceId:887c67ff-7681-4fea-8e9f-e7d3838766f9 sessionId:null ProcessName:test ProcessStep:4.3. Joinpoint:execution(void com.hooke.biz.TraceTest.doSomeThing2()) argsJson: returnJson: cost:15 ms!
1764 [Thread-2] INFO c.h.trace.aop.spring.TraceAspect - threadId:13 triceId:887c67ff-7681-4fea-8e9f-e7d3838766f9 sessionId:null ProcessName:test ProcessStep:4.1. Joinpoint:execution(void com.hooke.biz.TraceTest.doSomeThing2()) argsJson: returnJson: cost:15 ms!
1866 [Thread-4] INFO c.h.trace.aop.spring.TraceAspect - threadId:15 triceId:887c67ff-7681-4fea-8e9f-e7d3838766f9 sessionId:null ProcessName:test ProcessStep:4.4. Joinpoint:execution(void com.hooke.biz.TraceTest.doSomeThing2()) argsJson: returnJson: cost:0 ms!
1964 [Thread-5] INFO c.h.trace.aop.spring.TraceAspect - threadId:16 triceId:887c67ff-7681-4fea-8e9f-e7d3838766f9 sessionId:null ProcessName:test ProcessStep:4.5. Joinpoint:execution(void com.hooke.biz.TraceTest.doSomeThing2()) argsJson: returnJson: cost:0 ms!
2066 [Thread-6] INFO c.h.trace.aop.spring.TraceAspect - threadId:17 triceId:887c67ff-7681-4fea-8e9f-e7d3838766f9 sessionId:null ProcessName:test ProcessStep:4.6. Joinpoint:execution(void com.hooke.biz.TraceTest.doSomeThing2()) argsJson: returnJson: cost:0 ms!
2177 [Thread-7] INFO c.h.trace.aop.spring.TraceAspect - threadId:18 triceId:887c67ff-7681-4fea-8e9f-e7d3838766f9 sessionId:null ProcessName:test ProcessStep:4.7. Joinpoint:execution(void com.hooke.biz.TraceTest.doSomeThing2()) argsJson: returnJson: cost:1 ms!
2275 [Thread-8] INFO c.h.trace.aop.spring.TraceAspect - threadId:19 triceId:887c67ff-7681-4fea-8e9f-e7d3838766f9 sessionId:null ProcessName:test ProcessStep:4.8. Joinpoint:execution(void com.hooke.biz.TraceTest.doSomeThing2()) argsJson: returnJson: cost:0 ms!
2403 [Thread-9] INFO c.h.trace.aop.spring.TraceAspect - threadId:20 triceId:887c67ff-7681-4fea-8e9f-e7d3838766f9 sessionId:null ProcessName:test ProcessStep:4.9. Joinpoint:execution(void com.hooke.biz.TraceTest.doSomeThing2()) argsJson: returnJson: cost:0 ms!
2492 [Thread-10] INFO c.h.trace.aop.spring.TraceAspect - threadId:21 triceId:887c67ff-7681-4fea-8e9f-e7d3838766f9 sessionId:null ProcessName:test ProcessStep:4.10. Joinpoint:execution(void com.hooke.biz.TraceTest.doSomeThing2()) argsJson: returnJson: cost:0 ms!
2591 [Thread-11] INFO c.h.trace.aop.spring.TraceAspect - threadId:22 triceId:887c67ff-7681-4fea-8e9f-e7d3838766f9 sessionId:null ProcessName:test ProcessStep:4.11. Joinpoint:execution(void com.hooke.biz.TraceTest.doSomeThing2()) argsJson: returnJson: cost:0 ms!
2700 [Thread-12] INFO c.h.trace.aop.spring.TraceAspect - threadId:23 triceId:887c67ff-7681-4fea-8e9f-e7d3838766f9 sessionId:null ProcessName:test ProcessStep:4.12. Joinpoint:execution(void com.hooke.biz.TraceTest.doSomeThing2()) argsJson: returnJson: cost:0 ms!
2800 [main] INFO c.h.trace.aop.spring.TraceAspect - threadId:1 triceId:887c67ff-7681-4fea-8e9f-e7d3838766f9 sessionId:null ProcessName:test ProcessStep:5. Joinpoint:execution(void com.hooke.biz.TraceTest.doSomeThing2()) argsJson: returnJson: cost:0 ms!
```
没有合适的资源?快使用搜索试试~ 我知道了~
基于注解的轻量级java流程跟踪工具.zip
共39个文件
java:16个
xml:11个
class:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 7 浏览量
2024-03-24
11:32:08
上传
评论
收藏 38KB ZIP 举报
温馨提示
基于注解的轻量级java流程跟踪工具
资源推荐
资源详情
资源评论
收起资源包目录
基于注解的轻量级java流程跟踪工具.zip (39个子文件)
java0323
trace4j-example
pom.xml 3KB
src
main
resources
spring-applicationContext-aop.xml 1KB
logback.xml 673B
spring-applicationContext.xml 1KB
java
com
hooke
biz
TraceTest.java 816B
TestAspect.aj 357B
Main.java 2KB
target
classes
spring-applicationContext-aop.xml 1KB
logback.xml 673B
spring-applicationContext.xml 1KB
com
hooke
Main.class 2KB
biz
TraceTest.class 1KB
TestAspect.class 2KB
pom.xml 7KB
trace4j-core
pom.xml 4KB
src
test
java
com
hooke
trace
cache
TestTraceTree.java 804B
main
resources
logback.xml 671B
java
com
hooke
trace
TraceProcess.java 5KB
Trace.java 480B
cache
TraceArray.java 178B
TraceCache.java 169B
TraceStep.java 1KB
TraceNode.java 798B
TraceTree.java 4KB
manager
TraceInheritParamManager.java 1KB
TraceParamManager.java 1KB
TraceCacheManager.java 1KB
aop
spring
TraceAspect.java 518B
IAopTrace.java 279B
util
TraceUtil.java 4KB
target
classes
logback.xml 671B
test-classes
com
hooke
trace
cache
TestTraceTree.class 1KB
maven-status
maven-compiler-plugin
compile
default-compile
createdFiles.lst 477B
inputFiles.lst 784B
testCompile
default-testCompile
inputFiles.lst 0B
trace4j-core-1.0-SNAPSHOT.jar 13KB
maven-archiver
pom.properties 113B
.gitignore 24B
README.md 6KB
共 39 条
- 1
资源评论
Kwan的解忧杂货铺
- 粉丝: 1w+
- 资源: 3671
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- meta-llama-3-8b-instruct 的 model-00004-of-00004.safetensors
- IMG_0006.CR2.cr2
- 幸运红包娱乐微信小程序源码 多玩法安装简单
- packagecom5_QQ浏览器压缩包.zip
- MY3-3WHY-可以刷萤石H6C-V100-2C3WF
- 深度解析木马隐藏技术:核心原理与VMware网络实验指南
- pbootcms百度智能小程序插件
- 指令调度和延迟分支学习资料.rar
- HTML5小游戏【飞得更高跳跃游戏feidegenggao】游戏源码分享下载 - feidegenggao.zip
- 第一讲:单片机STC89C52+RA8889驱动控制彩屏(源码公开)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功