├── .coveralls.yml ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE.txt ├── README.md ├── auto-log-annotation ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── github │ └── houbb │ └── auto │ └── log │ ├── annotation │ └── AutoLog.java │ ├── api │ ├── IAutoLog.java │ ├── IAutoLogContext.java │ ├── IAutoLogObjectHandler.java │ ├── IAutoLogSampleCondition.java │ ├── IParamFilter.java │ └── IParamFilterContext.java │ └── exception │ └── AutoLogRuntimeException.java ├── auto-log-core-extra ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── springframework │ ├── core │ └── io │ │ └── InputStreamSource.java │ └── web │ └── multipart │ └── MultipartFile.java ├── auto-log-core ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── github │ │ └── houbb │ │ └── auto │ │ └── log │ │ └── core │ │ ├── bs │ │ └── AutoLogBs.java │ │ ├── constant │ │ └── AutoLogAttachmentKeyConst.java │ │ ├── core │ │ ├── impl │ │ │ ├── AbstractAutoLogContext.java │ │ │ ├── SimpleAutoLog.java │ │ │ └── SimpleAutoLogContext.java │ │ └── package-info.java │ │ ├── exception │ │ └── AutoLogException.java │ │ ├── package-info.java │ │ └── support │ │ ├── filter │ │ ├── package-info.java │ │ └── param │ │ │ ├── AbstractParamFilter.java │ │ │ ├── ParamFilterContext.java │ │ │ └── WebParamFilter.java │ │ ├── handler │ │ ├── AbstractAutoLogObjectHandler.java │ │ ├── AutoLogObjectHandlerBigMemoryDiscard.java │ │ ├── AutoLogObjectHandlerDubboResult.java │ │ ├── AutoLogObjectHandlerInit.java │ │ ├── AutoLogObjectHandlerRaw.java │ │ ├── AutoLogObjectHandlerWebDiscard.java │ │ └── AutoLogObjectHandlers.java │ │ ├── interceptor │ │ ├── AutoLogMethodInterceptor.java │ │ ├── cache │ │ │ └── AutoLogCacheInterceptor.java │ │ ├── chain │ │ │ ├── AutoLogCommonFilter.java │ │ │ ├── AutoLogFilterChainConst.java │ │ │ ├── AutoLogInvocation.java │ │ │ └── AutoLogInvoker.java │ │ ├── common │ │ │ ├── AbstractAutoLogCommonFilter.java │ │ │ ├── AutoLogCommonFilterContext.java │ │ │ └── AutoLogCommonGlobalAnnotation.java │ │ ├── dubbo │ │ │ ├── AbstractAutoLogDubboFilter.java │ │ │ ├── AutoLogDubboConsumerFilter.java │ │ │ ├── AutoLogDubboContext.java │ │ │ └── AutoLogDubboProviderFilter.java │ │ ├── jms │ │ │ ├── AutoLogJmsConsumerInterceptor.java │ │ │ └── AutoLogJmsProducerInterceptor.java │ │ ├── schedule │ │ │ └── AutoLogScheduleInterceptor.java │ │ └── web │ │ │ ├── client │ │ │ └── AutoLogHttpClientInterceptor.java │ │ │ ├── package-info.java │ │ │ └── server │ │ │ └── AutoLogHttpServerServletFilter.java │ │ ├── package-info.java │ │ ├── proxy │ │ ├── AutoLogProxy.java │ │ ├── IAutoLogProxy.java │ │ ├── cglib │ │ │ └── CglibProxy.java │ │ ├── dynamic │ │ │ ├── DynamicProxy.java │ │ │ └── package-info.java │ │ ├── none │ │ │ └── NoneProxy.java │ │ └── package-info.java │ │ └── sample │ │ ├── AutoLogSampleConditionAdaptive.java │ │ ├── AutoLogSampleConditionAdaptiveSchedule.java │ │ ├── AutoLogSampleConditionRate.java │ │ ├── AutoLogSampleConditions.java │ │ └── InnerRandomUtil.java │ └── resources │ └── META-INF │ ├── dubbo │ └── com.alibaba.dubbo.rpc.Filter │ └── services │ └── com.github.houbb.common.filter.api.CommonFilter ├── auto-log-spring ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── github │ └── houbb │ └── auto │ └── log │ └── spring │ ├── annotation │ └── EnableAutoLog.java │ ├── aop │ ├── AutoLogAdvice.java │ ├── AutoLogAdviceContext.java │ ├── AutoLogAop.java │ └── AutoLogDynamicPointcut.java │ ├── config │ ├── AutoLogAopConfig.java │ └── DefaultAutoLogGlobalConfig.java │ ├── context │ └── SpringAopAutoLogContext.java │ └── package-info.java ├── auto-log-springboot-starter ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── github │ │ └── houbb │ │ └── auto │ │ └── log │ │ └── springboot │ │ └── starter │ │ ├── config │ │ └── AutoLogAutoConfig.java │ │ └── package-info.java │ └── resources │ └── META-INF │ └── spring.factories ├── auto-log-test ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── houbb │ │ │ └── auto │ │ │ └── log │ │ │ └── test │ │ │ ├── config │ │ │ └── SpringConfig.java │ │ │ ├── dynamic │ │ │ ├── SpringDynamicConfig.java │ │ │ └── service │ │ │ │ ├── MyAddressService.java │ │ │ │ └── MyUserService.java │ │ │ ├── filter │ │ │ └── MyParamFilter.java │ │ │ ├── interceptor │ │ │ └── MyAutoLogInterceptor.java │ │ │ ├── package-info.java │ │ │ └── service │ │ │ ├── DiscardService.java │ │ │ ├── UserService.java │ │ │ ├── annotation │ │ │ └── AutoLogMethod.java │ │ │ └── impl │ │ │ ├── ClassAnnotationService.java │ │ │ ├── DefineService.java │ │ │ ├── MenuServiceImpl.java │ │ │ ├── MethodAtServiceImpl.java │ │ │ ├── PrivateUserServiceImpl.java │ │ │ ├── SampleRateServiceImpl.java │ │ │ └── UserServiceImpl.java │ └── resources │ │ ├── autoLogConfig.properties │ │ └── log4j2.xml │ └── test │ ├── java │ └── com │ │ └── github │ │ └── houbb │ │ └── auto │ │ └── log │ │ ├── core │ │ └── bs │ │ │ ├── AutoLogBsRateTest.java │ │ │ ├── AutoLogBsTest.java │ │ │ ├── AutoLogCoreDiscardTest.java │ │ │ └── package-info.java │ │ ├── dynamic │ │ └── SpringDynamicServiceTest.java │ │ └── spring │ │ ├── SpringPrivateServiceTest.java │ │ ├── SpringServiceMethodTest.java │ │ └── SpringServiceTest.java │ └── resources │ └── META-INF │ └── services │ └── com.github.houbb.common.filter.api.CommonFilter ├── cgit.bat ├── cgit.sh ├── doc ├── 02-dynamic-pointcut.md ├── CI集成.md ├── issues │ └── 个人思考.md ├── user │ └── 01-项目模块.md ├── 发布流程.md └── 版本迭代规范.md ├── github_init.bat ├── pom.xml ├── release.bat ├── release.sh └── release_rm.sh /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: travis-ci -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # maven ignore 2 | target/ 3 | *.jar 4 | *.war 5 | *.zip 6 | *.tar 7 | *.tar.gz 8 | 9 | # eclipse ignore 10 | .settings/ 11 | .project 12 | .classpath 13 | 14 | # idea ignore 15 | .idea/ 16 | *.ipr 17 | *.iml 18 | *.iws 19 | 20 | # temp ignore 21 | *.log 22 | *.cache 23 | *.diff 24 | *.patch 25 | *.tmp 26 | *.java~ 27 | *.properties~ 28 | *.xml~ 29 | 30 | # system ignore 31 | .DS_Store 32 | Thumbs.db 33 | 34 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - openjdk8 4 | install: mvn install -DskipTests=true -Dmaven.javadoc.skip=true 5 | script: mvn test 6 | after_success: 7 | - mvn clean cobertura:cobertura coveralls:report 8 | 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 变更日志 2 | 3 | | 类型 | 说明 | 4 | |:----|:----| 5 | | A | 新增 | 6 | | U | 更新 | 7 | | D | 删除 | 8 | | T | 测试 | 9 | | O | 优化 | 10 | | F | 修复BUG | 11 | 12 | # release_0.0.1 13 | 14 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 15 | |:---|:---|:---|:---|:--| 16 | | 1 | A | 基本的特性实现 | 2020-5-25 13:43:05 | | 17 | 18 | # release_0.0.2 19 | 20 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 21 | |:---|:---|:---|:---|:--| 22 | | 1 | A | 支持声明式的代理实现 | 2020-5-29 16:25:32 | | 23 | 24 | # release_0.0.3 25 | 26 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 27 | |:---|:---|:---|:---|:--| 28 | | 1 | A | 整合 spring 实现 | 2020-5-30 12:28:05 | | 29 | 30 | # release_0.0.4 31 | 32 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 33 | |:---|:---|:---|:---|:--| 34 | | 1 | A | 新增慢日志阈值特性 | 2020-6-1 16:45:14 | | 35 | | 2 | O | 代理部分使用 aop 共有模块 | 2020-6-1 16:49:00 | | 36 | 37 | # release_0.0.5 38 | 39 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 40 | |:---|:---|:---|:---|:--| 41 | | 1 | A | spring-boot 整合实现 | 2020-8-6 09:47:19 | | 42 | 43 | # release_0.0.6 44 | 45 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 46 | |:---|:---|:---|:---|:--| 47 | | 1 | A | 添加非接口的支持 | 2020-9-2 21:55:25 | | 48 | 49 | # release_0.0.7 50 | 51 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 52 | |:---|:---|:---|:---|:--| 53 | | 1 | A | 添加 description 特性 | 2020-9-6 10:13:09 | | 54 | | 2 | O | 优化日志实现 | 2020-9-6 10:13:09 | | 55 | 56 | # release_0.0.8 57 | 58 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 59 | |:---|:---|:---|:---|:--| 60 | | 1 | A | 添加 traceId 特性 | 2020-9-6 21:37:43 | | 61 | 62 | # release_0.0.9 63 | 64 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 65 | |:---|:---|:---|:---|:--| 66 | | 1 | A | 添加支持自定义日志策略 | 2020-9-25 21:37:43 | | 67 | 68 | # release_0.0.10 69 | 70 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 71 | |:---|:---|:---|:---|:--| 72 | | 1 | A | 支持类级别自定义注解 | 2020-9-25 21:37:43 | | 73 | | 2 | A | 使用拦截器替代 v0.0.9 的实现方式 | 2020-9-25 21:37:43 | | 74 | | 3 | O | 使用 fastJson 替代原来的 toString() | 2020-9-25 21:37:43 | | 75 | 76 | # release_0.0.11 77 | 78 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 79 | |:---|:---|:---|:---|:--| 80 | | 1 | F | 添加 HttpRequest/HttpResponse 等参数的过滤 | 2020-9-25 21:37:43 | | 81 | 82 | # release_0.0.12 83 | 84 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 85 | |:---|:---|:---|:---|:--| 86 | | 1 | A | 支持入参指定 Filter 特性 | 2020-9-26 10:01:11 | | 87 | 88 | # release_0.0.13 89 | 90 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 91 | |:---|:---|:---|:---|:--| 92 | | 1 | A | 调整 WebParamFilter 为默认过滤策略 | 2020-9-26 16:01:15 | | 93 | | 2 | O | 使用类替代原来的接口判断方式 | 2020-9-26 16:01:15 | | 94 | 95 | # release_0.0.14 96 | 97 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 98 | |:---|:---|:---|:---|:--| 99 | | 1 | A | 将 AutoLogUtil 提取为单独的工具类,便于获取 traceId | 2020-9-26 16:01:15 | | 100 | 101 | # release_0.0.15 102 | 103 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 104 | |:---|:---|:---|:---|:--| 105 | | 1 | A | 添加文件信息的过滤 | 2021-9-20 16:01:15 | | 106 | 107 | # release_0.0.16 108 | 109 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 110 | |:---|:---|:---|:---|:--| 111 | | 1 | A | 简化操作日志,移除 @TraceId | 2022-12-20 16:01:15 | | 112 | 113 | # release_0.1.0 114 | 115 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 116 | |:---|:---|:---|:---|:--| 117 | | 1 | A | 更新 heaven/fastjson 版本依赖 | 2023-03-22 16:01:15 | | 118 | 119 | # release_0.2.0 120 | 121 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 122 | |:---|:---|:--------------|:--------------------|:--| 123 | | 1 | A | 附加包独立, 便于单独排除 | 2023-07-20 16:01:15 | | 124 | 125 | # release_0.3.0 126 | 127 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 128 | |:---|:---|:----------------|:--------------------|:--| 129 | | 1 | A | 支持 pointcut 自定义 | 2023-07-21 16:01:15 | | 130 | 131 | # release_0.4.0 132 | 133 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 134 | |:---|:-----|:-----------------------|:--------------------|:--| 135 | | 1 | A | 使用 dubbo chain 模式实现拦截器 | 2023-08-06 16:01:15 | | 136 | | 2 | O | 优化日志格式 | 2023-08-06 16:01:15 | | 137 | 138 | # release_0.5.0 139 | 140 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 141 | |:---|:-----|:-----------------------|:--------------------|:--| 142 | | 1 | A | 新增采样条件,指定比例采样 | 2023-08-18 16:01:15 | | 143 | 144 | # release_0.6.0 145 | 146 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 147 | |:---|:-----|:-----------------------|:--------------------|:--| 148 | | 1 | A | 新增自适应采样 | 2023-08-20 16:01:15 | | 149 | 150 | # release_0.7.0 151 | 152 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 153 | |:---|:-----|:-------------|:--------------------|:--| 154 | | 1 | A | 添加 dubbo 拦截器 | 2023-09-18 16:01:15 | | 155 | 156 | # release_0.8.0 157 | 158 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 159 | |:---|:-----|:-------------|:--------------------|:--| 160 | | 1 | A | 添加 log4j2 默认日志依赖 | 2023-09-27 16:01:15 | | 161 | | 2 | O | 优化 filter,调整 dubbo 位置 | 2023-09-27 16:01:15 | | 162 | 163 | # release_0.9.0 164 | 165 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 166 | |:---|:-----|:-------------|:--------------------|:--| 167 | | 1 | A | 添加统一的 filter | 2023-09-27 16:01:15 | | 168 | 169 | # release_0.10.0 170 | 171 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 172 | |:---|:-----|:--------------------------------|:--------------------|:--| 173 | | 1 | A | 添加 result filter | 2023-09-27 16:01:15 | | 174 | | 2 | A | 添加 param filter bigdata discard | 2023-09-27 16:01:15 | | 175 | 176 | # release_0.11.0 177 | 178 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 179 | |:---|:-----|:--------------------------------|:--------------------|:--| 180 | | 1 | A | 添加定长截断 | 2023-10-10 16:01:15 | | 181 | | 2 | O | 优化丢弃策略 | 2023-10-10 16:01:15 | | 182 | 183 | # release_0.12.0 184 | 185 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 186 | |:---|:-----|:-------------|:--------------------|:--| 187 | | 1 | O | 移除 log4j2 依赖 | 2024-01-29 16:01:15 | | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2016 ShenHuaJie iBase4J@163.com 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | 204 | ====================================================================== 205 | 206 | Apache许可证 207 | 版本 2.0,2004年1月 208 | http://www.apache.org/licenses/ 209 | 210 | 使用、重生成及分发的术语和条件: 211 | 212 | 1.定义 213 | 214 | "许可证"是指根据本文档第1到第9部分关于使用、重生成和分发的术语和条件。 215 | 216 | "许可证颁发者"是指版权所有者或者由版权所有者批准的授权许可证的实体。 217 | 218 | "法律实体"是指实施实体和进行控制的所有其它实体受该实体控制,或者受该实体集中控制。 219 | 根据此定义,"控制"是指(i)让无论是否签订协议的上述实体,进行指导或管理的直接权利或间接权利, 220 | 或者(ii)拥有百分之五十(50%)或以上已发行股票的所有者,或者(iii)上述实体的实权所有者。 221 | 222 | "用户"(或"用户的")是指行使本许可证所授予权限的个人或法律实体。 223 | 224 | "源程序"形式是指对包含但不限制软件源代码、文档源程序和配置文件进行修改的首选形式。 225 | 226 | "目标"形式是指对源程序形式进行机械转换或翻译的任何形式,包括但不限于对编译的目标代码, 227 | 生成的文件以及转换为其它媒体类型。 228 | 229 | "作品"是指根据本许可证所制作的源程序形式或目标形式的著作,在著作中包含的或附加的版权通知 230 | (在下面附录中提供了一个示例)。 231 | 232 | "衍生作品"是指基于作品(或从作品衍生而来)的源程序形式或目标形式的任何作品,以及编辑修订、 233 | 注释、详细描述或其它修订等构成原创著作作品的整体。根据本许可证,衍生作品不得包括与作品及其 234 | 衍生作品分离之作品,或仅与作品及其衍生作品的接口相链接(或按名称结合)之作品。 235 | 236 | "贡献"是指任何著作作品,包括作品的原始版本和对该作品或衍生作品所做的任何修订或补充, 237 | 意在提交给许可证颁发者以让版权所有者或代表版权所有者的授权个人或法律实体包含在其作品中。 238 | 根据此定义,"提交"一词表示发送给许可证颁发者或其代表人,任何电子的、口头的或书面的交流信息形式, 239 | 包括但不限于在由许可证颁发者或者代表其管理的电子邮件清单、源代码控制系统、以及发布跟踪系统上为 240 | 讨论和提高作品的交流,但不包括由版权所有者以书面形式明显标注或指定为"非贡献"的交流活动。 241 | 242 | "贡献者"是指许可证颁发者和代表从许可证颁发者接受之贡献的并随后包含在作品之贡献中的任何个人或法律实体。 243 | 244 | 2.版权许可证的授予 245 | 246 | 根据本许可证的条款,每个贡献者授予用户永久性的、全球性的、非专有性的、免费的、无版权费的、 247 | 不可撤销的版权许可证以源程序形式或目标形式复制、准备衍生作品、公开显示、公开执行、 248 | 授予分许可证、以及分发作品和这样的衍生作品。 249 | 250 | 3.专利许可证的授予 251 | 252 | 根据本许可证的条款,每个贡献者授予用户永久性的、全球性的、非专有性的、免费的、无版权费的、 253 | 不可撤销的(除在本部分进行说明)专利许可证对作品进行制作、让人制作、使用、提供销售、销售、 254 | 进口和其它转让,且这样的许可证仅适用于在所递交作品的贡献中因可由单一的或多个这样的贡献者 255 | 授予而必须侵犯的申请专利。如果用户对任何实体针对作品或作品中所涉及贡献提出因直接性或贡献性 256 | 专利侵权而提起专利法律诉讼(包括交互诉讼请求或反索赔),那么根据本许可证,授予用户针对作品 257 | 的任何专利许可证将在提起上述诉讼之日起终止。 258 | 259 | 4.重新分发 260 | 261 | 用户可在任何媒介中复制和分发作品或衍生作品之副本,无论是否修订,还是以源程序形式或目标形式, 262 | 条件是用户需满足下列条款: 263 | 264 | a) 用户必须为作品或衍生作品的任何其他接收者提供本许可证的副本;并且 265 | 266 | b) 用户必须让任何修改过的文件附带明显的通知,声明用户已更改文件;并且 267 | 268 | c) 用户必须从作品的源程序形式中保留衍生作品源程序形式的用户所分发的所有版权、专利、 269 | 商标和属性通知,但不包括不属于衍生作品任何部分的类似通知;并且 270 | 271 | d) 如果作品将"通知"文本文件包括为其分发作品的一部分,那么用户分发的任何衍生作品中须至少 272 | 在下列地方之一包括,在这样的通知文件中所包含的属性通知的可读副本,但不包括那些不属于衍生 273 | 作品任何部分的通知:在作为衍生作品一部分而分发的通知文本文件中;如果与衍生作品一起提供则 274 | 在源程序形式或文件中;或者通常作为第三方通知出现的时候和地方,在衍生作品中产生的画面中。 275 | 通知文件的内容仅供信息提供,并未对许可证进行修改。用户可在其分发的衍生作品中在作品的通知 276 | 文本后或作为附录添加自己的属性通知,条件是附加的属性通知不得构成修改本许可证。 277 | 278 | 用户可以为自身所做出的修订添加自己的版权声明并可对自身所做出修订内容或为这样的衍生作品作为 279 | 整体的使用、复制或分发提供附加或不同的条款,条件是用户对作品的使用、复制和分发必须符合本许 280 | 可证中声明的条款。 281 | 282 | 5.贡献的提交。 283 | 284 | 除非用户明确声明,在作品中由用户向许可证颁发者的提交若要包含在贡献中,必须在无任何附加条款下 285 | 符合本许可证的条款。尽管上面如此规定,执行许可证颁发者有关贡献的条款时,任何情况下均不得替代 286 | 或修改任何单独许可证协议的条款。 287 | 288 | 6.商标。本许可证并未授予用户使用许可证颁发者的商号、商标、服务标记或产品名称,除非将这些名称 289 | 用于合理性和惯例性描述作品起源和复制通知文件的内容时。 290 | 291 | 7.保证否认条款。除非因适用法律需要或书面同意,许可证颁发者以"按原样"基础提供作品(并且每个 292 | 贡献者提供其贡献),无任何明示的或暗示的保证或条件,包括但不限于关于所有权、不侵权、 293 | 商品适销性、或适用性的保证或条件。用户仅对使用或重新分发作品的正确性负责,并需承担根据本 294 | 许可证行使权限时的任何风险。 295 | 296 | 8.责任限制条款。在任何情况下并根据任何法律,无论是因侵权(包括过失)或根据合同,还是其它原因, 297 | 除非根据适用法律需要(例如故意行为和重大过失行为)或经书面同意,即使贡献者事先已被告知发生 298 | 损害的可能性,任何贡献者不就用户因使用本许可证或不能使用或无法使用作品(包括但不限于商誉损失、 299 | 停工、计算机失效或故障,或任何商业损坏或损失)而造成的损失,包括直接的、非直接的、特殊的、意外 300 | 的或间接的字符损坏而负责。 301 | 302 | 9.接受保证或附加责任。重新分发作品或及其衍生作品时,用户可选择提供或为符合本许可证承担之支持、 303 | 担保、赔偿或其它职责义务和/或权利而收取费用。但是,在承担上述义务时,用户只可代表用户本身和 304 | 用户本身责任来执行,无需代表任何其它贡献者,并且用户仅可保证、防护并保持每个贡献者不受任何 305 | 因此而产生的责任或对因用户自身承担这样的保证或附加责任而对这样的贡献者所提出的索赔。 306 | 307 | 条款结束 308 | 309 | 附录:如何向用户作品中应用Apache许可证。 310 | 311 | 若要向用户作品应用Apache许可证,请附加下列样本通知,将括号"[]"中的字段以用户自身的 312 | 区分信息来替换(但不包括括号)。文本必须以文件格式适当的注释句法包含在其中。 313 | 另外建议将文件名或类别名以及目的说明包含在相同的"打印页"上作为版权通知,以更加容易的区分出第三方档案。 314 | 315 | 版权所有 2016 ShenHuaJie iBase4J@163.com 根据2.0版本Apache许可证("许可证")授权; 316 | 根据本许可证,用户可以不使用此文件。 317 | 318 | 用户可从下列网址获得许可证副本:http://www.apache.org/licenses/LICENSE-2.0 319 | 除非因适用法律需要或书面同意,根据许可证分发的软件是基于"按原样"基础提供, 320 | 无任何明示的或暗示的保证或条件。详见根据许可证许可下,特定语言的管辖权限和限制。 321 | 322 | ======================================================= 323 | 324 | 简要解释: 325 | 326 | 1.需要给代码的用户一份Apache Licence 327 | 2.如果你修改了代码,需要在被修改的文件中说明。 328 | 3.在延伸的代码中(修改和有源代码衍生的代码中)需要带有原来代码中的协议,商标, 329 | 专利声明和其他原来作者规定需要包含的说明。 330 | 4.如果再发布的产品中包含一个Notice文件,则在Notice文件中需要带有 Apache Licence。 331 | 你可以在Notice中增加自己的许可,但不可以表现为对Apache Licence构成更改。 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # auto-log 2 | 3 | [auto-log](https://github.com/houbb/auto-log) 是一款为 java 设计的自动日志监控框架。 4 | 5 | [![Build Status](https://travis-ci.com/houbb/auto-log.svg?branch=master)](https://travis-ci.com/houbb/auto-log) 6 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.houbb/auto-log/badge.svg)](http://mvnrepository.com/artifact/com.github.houbb/auto-log) 7 | [![](https://img.shields.io/badge/license-Apache2-FF0080.svg)](https://github.com/houbb/auto-log/blob/master/LICENSE.txt) 8 | [![Open Source Love](https://badges.frapsoft.com/os/v2/open-source.svg?v=103)](https://github.com/houbb/auto-log) 9 | 10 | ## 创作目的 11 | 12 | 经常会写一些工具,有时候手动加一些日志很麻烦,引入 spring 又过于大材小用。 13 | 14 | 所以希望从从简到繁实现一个工具,便于平时使用。 15 | 16 | ## 特性 17 | 18 | - 基于注解+字节码,配置灵活 19 | 20 | - 自动适配常见的日志框架 21 | 22 | - 支持编程式的调用 23 | 24 | - 支持注解式,完美整合 spring 25 | 26 | - 支持整合 spring-boot 27 | 28 | - 支持慢日志阈值指定,耗时,入参,出参,异常信息等常见属性指定 29 | 30 | - 支持 traceId 特性 31 | 32 | - 支持类级别定义注解 33 | 34 | - 支持自定义拦截器和过滤器 35 | 36 | - 支持 spring aop 注解切面自定义 37 | 38 | - 支持类似 dubbo filter 的拦截器链式调用 39 | 40 | - 支持日志条件输出,支持日志自适应输出 41 | 42 | - 支持日志的超长截断+丢弃策略,避免极端情况的性能问题 43 | 44 | ## 项目推荐 45 | 46 | 下面是一些日志、加解密、脱敏安全相关的库推荐: 47 | 48 | | 项目 | 介绍 | 49 | |:----------------------------------------------------------------------|:----------------------| 50 | | [sensitive-word](https://github.com/houbb/sensitive-word) | 高性能敏感词核心库 | 51 | | [sensitive-word-admin](https://github.com/houbb/sensitive-word-admin) | 敏感词控台,前后端分离 | 52 | | [sensitive](https://github.com/houbb/sensitive) | 高性能日志脱敏组件 | 53 | | [auto-log](https://github.com/houbb/auto-log) | 统一日志切面组件,支持全链路traceId | 54 | | [encryption-local](https://github.com/houbb/encryption-local) | 离线加密机组件 | 55 | | [encryption](https://github.com/houbb/encryption) | 加密机标准API+本地客户端 | 56 | | [encryption-server](https://github.com/houbb/encryption-server) | 加密机服务 | 57 | 58 | ## 变更日志 59 | 60 | > [变更日志](https://github.com/houbb/auto-log/blob/master/CHANGELOG.md) 61 | 62 | V0.11.0 变更 63 | 64 | - 支持日志的超长截断+丢弃策略,避免极端情况的性能问题 65 | 66 | ## 拓展阅读 67 | 68 | [日志开源组件(一)java 注解结合 spring aop 实现自动输出日志](https://houbb.github.io/2023/08/06/auto-log-01-overview) 69 | 70 | [日志开源组件(二)java 注解结合 spring aop 实现日志traceId唯一标识](https://houbb.github.io/2023/08/06/auto-log-02-trace-id) 71 | 72 | [日志开源组件(三)java 注解结合 spring aop 自动输出日志新增拦截器与过滤器](https://houbb.github.io/2023/08/06/auto-log-03-filter) 73 | 74 | [日志开源组件(四)如何动态修改 spring aop 切面信息?让自动日志输出框架更好用](https://houbb.github.io/2023/08/06/auto-log-04-dynamic-aop) 75 | 76 | [日志开源组件(五)如何将 dubbo filter 拦截器原理运用到日志拦截器中?](https://houbb.github.io/2023/08/06/auto-log-05-dubbo-interceptor) 77 | 78 | [日志开源组件(六)Adaptive Sampling 自适应采样](https://mp.weixin.qq.com/s/9JH3WfR6Y474LCbY2mZxZQ) 79 | 80 | [高性能日志脱敏组件(一)java 日志脱敏框架 sensitive,优雅的打印脱敏日志](https://mp.weixin.qq.com/s/xzQNDF7s705iurk7N0uheQ) 81 | 82 | [高性能日志脱敏组件(二)金融用户敏感数据如何优雅地实现脱敏?](https://mp.weixin.qq.com/s/ljChFiNLzV6GLaUDjehA0Q) 83 | 84 | [高性能日志脱敏组件(三)日志脱敏之后,无法根据信息快速定位怎么办?](https://mp.weixin.qq.com/s/tZqOH_8QTKrD1oaclNoewg) 85 | 86 | [高性能日志脱敏组件(四)基于 log4j2 插件实现统一日志脱敏,性能远超正则替换](https://mp.weixin.qq.com/s/ZlWRqT7S92aXFuy-l9Uh3Q) 87 | 88 | [高性能日志脱敏组件(五)已支持 log4j2 和 logback 插件](https://mp.weixin.qq.com/s/3ARK6PW7pyUhAbO2ctnndg) 89 | 90 | # 快速开始 91 | 92 | ## maven 引入 93 | 94 | ```xml 95 | 96 | com.github.houbb 97 | auto-log-core 98 | 0.12.0 99 | 100 | ``` 101 | 102 | ## 入门案例 103 | 104 | ```java 105 | UserService userService = AutoLogHelper.proxy(new UserServiceImpl()); 106 | userService.queryLog("1"); 107 | ``` 108 | 109 | - 日志如下 110 | 111 | ``` 112 | 信息: [TID=9d5ad747342e4f909d42001f1419c58b][METHOD=com.github.houbb.auto.log.test.service.impl.UserServiceImpl.queryLog:java.lang.String#查询日志][PARAM=["1"]][RESULT="result-1"][COST=607 ms] 113 | ``` 114 | 115 | ### 属性说明 116 | 117 | | 属性 | 说明 | 118 | |:-------|:------| 119 | | TID | 日志跟踪号 | 120 | | METHOD | 方法签名 | 121 | | PARAM | 方法入参 | 122 | | RESULT | 方法出参 | 123 | | COST | 方法耗时 | 124 | | SLOW-THRESHOLD | 慢日志阈值 | 125 | | EXCEPTION | 方法异常 | 126 | 127 | ### 代码 128 | 129 | 其中方法实现如下: 130 | 131 | - UserService.java 132 | 133 | ```java 134 | public interface UserService { 135 | 136 | String queryLog(final String id); 137 | 138 | } 139 | ``` 140 | 141 | - UserServiceImpl.java 142 | 143 | 直接使用注解 `@AutoLog` 指定需要打日志的方法即可。 144 | 145 | ```java 146 | public class UserServiceImpl implements UserService { 147 | 148 | @Override 149 | @AutoLog(description = "查询日志", enableTraceId = true) 150 | public String queryLog(String id) { 151 | return "result-"+id; 152 | } 153 | 154 | } 155 | ``` 156 | 157 | # 注解说明 158 | 159 | ## @AutoLog 160 | 161 | 核心注解 `@AutoLog` 的属性说明如下: 162 | 163 | | 属性 | 类型 | 默认值 | 说明 | 164 | |:--|:--|:--|:--| 165 | | enable | boolean | true | 是否启用 | 166 | | param | boolean | true | 是否打印入参 | 167 | | result | boolean | true | 是否打印出参 | 168 | | costTime | boolean | false | 是否打印耗时 | 169 | | exception | boolean | true | 是否打印异常 | 170 | | slowThresholdMills | long | -1 | 当这个值大于等于 0 时,且耗时超过配置值,会输出慢日志 | 171 | | description | string |"" | 方法描述,默认选择方法名称 | 172 | | paramFilter | Class | WebParamFilter | 入参过滤器,支持自定义 | 173 | | traceId | Class | Id.class | 日志跟踪号生成策略 | 174 | | enableTraceId | boolean | true | 是否启用 traceId 的变化 | 175 | 176 | 使用建议,在入口的方法中设置 `enableTraceId=true`,会统一设置 traceId,贯穿整个日志周期。 底层依赖的 service/biz 层等,设置为 false 即可。 177 | 178 | # 自定义策略 179 | 180 | ## 自定义日志拦截器(interceptor) 181 | 182 | ### 内置拦截器 183 | 184 | `AutoLogCommonFilter` 默认日志增强实现 185 | 186 | ### 定义 187 | 188 | 直接实现 `CommonFilter` 类,并且实现对应的方法即可。 189 | 190 | ```java 191 | package com.github.houbb.auto.log.test.interceptor; 192 | 193 | import com.github.houbb.auto.log.core.constant.AutoLogAttachmentKeyConst; 194 | import com.github.houbb.common.filter.annotation.FilterActive; 195 | import com.github.houbb.common.filter.api.CommonFilter; 196 | import com.github.houbb.common.filter.api.Invocation; 197 | import com.github.houbb.common.filter.api.Invoker; 198 | import com.github.houbb.common.filter.api.Result; 199 | import com.github.houbb.common.filter.exception.CommonFilterException; 200 | 201 | /** 202 | * 自定义日志拦截器 203 | * @author binbin.hou 204 | * @since 0.0.12 205 | */ 206 | @FilterActive(order = 1) 207 | public class MyAutoLogInterceptor implements CommonFilter { 208 | 209 | @Override 210 | public Result invoke(Invoker invoker, Invocation invocation) throws CommonFilterException { 211 | final String tid = (String) invocation.getAttachment(AutoLogAttachmentKeyConst.AUTO_LOG_TRACE_ID); 212 | System.out.println("my test filter before " + tid); 213 | Result result = invoker.invoke(invocation); 214 | System.out.println("my test filter after " + tid); 215 | 216 | return result; 217 | } 218 | 219 | } 220 | ``` 221 | 222 | 我们可以通过 `@FilterActive(order = 1)` 指定拦截器执行的顺序,数值越小,越先执行。 223 | 224 | `invocation.getAttachment(AutoLogAttachmentKeyConst.AUTO_LOG_TRACE_ID)` 可以获取 invocation 中传递的属性。 225 | 226 | ### 使用 227 | 228 | SPI 指定 229 | 230 | 创建文件 `resources\META-INF\services\com.github.houbb.common.filter.api.CommonFilter` 231 | 232 | 在文件中指定我们定义的接口: 233 | 234 | ``` 235 | com.github.houbb.auto.log.test.interceptor.MyAutoLogInterceptor 236 | ``` 237 | 238 | ### 测试效果 239 | 240 | ``` 241 | my test filter before 2bc181d4efb8408e948072022c9227c0 242 | my test filter after 2bc181d4efb8408e948072022c9227c0 243 | 八月 06, 2023 8:13:19 下午 com.github.houbb.auto.log.core.support.interceptor.chain.AutoLogCommonFilter info 244 | 信息: [TID=2bc181d4efb8408e948072022c9227c0][METHOD=com.github.houbb.auto.log.test.service.impl.UserServiceImpl.queryLog:java.lang.String#查询日志][PARAM=["1"]][RESULT="result-1"][COST=535 ms] 245 | ``` 246 | 247 | ## 自定义入参过滤器(paramFilter) 248 | 249 | ### 内置 250 | 251 | `WebParamFilter` 主要用于过滤 HttpRequest HttpServlet 等无法直接 JSON 序列化的对象。 252 | 253 | ### 自定义 254 | 255 | 直接继承 `AbstractParamFilter` 类实现对应的方法即可。 256 | 257 | ```java 258 | public class MyParamFilter extends AbstractParamFilter { 259 | 260 | @Override 261 | protected Object[] doFilter(Object[] params) { 262 | Object[] newParams = new Object[1]; 263 | newParams[0] = "设置我我想要的值"; 264 | return newParams; 265 | } 266 | 267 | } 268 | ``` 269 | 270 | ### 使用 271 | 272 | 指定对应的参数过滤器。这样,无论入参是什么,都会变成我们指定的 `[设置我我想要的值]`。 273 | 274 | ```java 275 | @AutoLog(paramFilter = MyParamFilter.class) 276 | public String paramFilter() { 277 | return "自定义入参过滤器"; 278 | } 279 | ``` 280 | 281 | 282 | # spring 整合使用 283 | 284 | 完整示例参考 [SpringServiceTest](https://github.com/houbb/auto-log/tree/master/auto-log-test/src/test/java/com/github/houbb/auto/log/spring/SpringServiceTest.java) 285 | 286 | ## maven 引入 287 | 288 | ```xml 289 | 290 | com.github.houbb 291 | auto-log-spring 292 | 0.12.0 293 | 294 | ``` 295 | 296 | ## 注解声明 297 | 298 | 使用 `@EnableAutoLog` 启用自动日志输出 299 | 300 | ```java 301 | @Configurable 302 | @ComponentScan(basePackages = "com.github.houbb.auto.log.test.service") 303 | @EnableAutoLog 304 | public class SpringConfig { 305 | } 306 | ``` 307 | 308 | ## 测试代码 309 | 310 | ```java 311 | @ContextConfiguration(classes = SpringConfig.class) 312 | @RunWith(SpringJUnit4ClassRunner.class) 313 | public class SpringServiceTest { 314 | 315 | @Autowired 316 | private UserService userService; 317 | 318 | @Test 319 | public void queryLogTest() { 320 | userService.queryLog("1"); 321 | } 322 | 323 | } 324 | ``` 325 | 326 | - 输出结果 327 | 328 | ``` 329 | 信息: public java.lang.String com.github.houbb.auto.log.test.service.impl.UserServiceImpl.queryLog(java.lang.String) param is [1] 330 | 五月 30, 2020 12:17:51 下午 com.github.houbb.auto.log.core.support.interceptor.AutoLogMethodInterceptor info 331 | 信息: public java.lang.String com.github.houbb.auto.log.test.service.impl.UserServiceImpl.queryLog(java.lang.String) result is result-1 332 | 五月 30, 2020 12:17:51 下午 org.springframework.context.support.GenericApplicationContext doClose 333 | ``` 334 | 335 | ## 切面自定义 336 | 337 | ### 原理解释 338 | 339 | spring aop 的切面读取自 `@Value("${auto.log.pointcut}")`,默认为值 `@within(com.github.houbb.auto.log.annotation.AutoLog)||@annotation(com.github.houbb.auto.log.annotation.AutoLog)` 340 | 341 | 也就是默认是读取被 `@AutoLog` 指定的方法或者类。 342 | 343 | 当然,这并不够方便,我们希望可以想平时写 aop 注解一样,指定 spring aop 的扫描范围,直接在 spring 中指定一下 `auto.log.pointcut` 的属性值即可。 344 | 345 | ### 测试例子 346 | 347 | > [完整测试代码](https://github.com/houbb/auto-log/blob/master/auto-log-test/src/test/java/com/github/houbb/auto/log/dynamic/SpringDynamicServiceTest.java) 348 | 349 | 我们在配置文件 `autoLogConfig.properties` 中自定义下包扫描的范围: 350 | 351 | ``` 352 | auto.log.pointcut=execution(* com.github.houbb.auto.log.test.dynamic.service.MyAddressService.*(..)) 353 | ``` 354 | 355 | 自定义测试 service 356 | 357 | ```java 358 | package com.github.houbb.auto.log.test.dynamic.service; 359 | 360 | import org.springframework.stereotype.Service; 361 | 362 | @Service 363 | public class MyAddressService { 364 | 365 | public String queryAddress(String id) { 366 | return "address-" + id; 367 | } 368 | 369 | } 370 | ``` 371 | 372 | 自定义 spring 配置,指定我们定义的配置文件。springboot 啥的,可以直接放在 application.properties 中指定,此处仅作为演示。 373 | 374 | ```java 375 | @Configurable 376 | @ComponentScan(basePackages = "com.github.houbb.auto.log.test.dynamic.service") 377 | @EnableAutoLog 378 | @PropertySource("classpath:autoLogConfig.properties") 379 | public class SpringDynamicConfig { 380 | } 381 | ``` 382 | 383 | 测试 384 | 385 | ```java 386 | @ContextConfiguration(classes = SpringDynamicConfig.class) 387 | @RunWith(SpringJUnit4ClassRunner.class) 388 | public class SpringDynamicServiceTest { 389 | 390 | @Autowired 391 | private MyAddressService myAddressService; 392 | 393 | @Autowired 394 | private MyUserService myUserService; 395 | 396 | @Test 397 | public void queryUserTest() { 398 | // 不会被日志拦截 399 | myUserService.queryUser("1"); 400 | } 401 | 402 | @Test 403 | public void queryAddressTest() { 404 | // 会被日志拦截 405 | myAddressService.queryAddress("1"); 406 | } 407 | 408 | } 409 | ``` 410 | 411 | # springboot 整合使用 412 | 413 | ## maven 引入 414 | 415 | ```xml 416 | 417 | com.github.houbb 418 | auto-log-springboot-starter 419 | 0.12.0 420 | 421 | ``` 422 | 423 | 只需要引入 jar 即可,其他的什么都不用配置。 424 | 425 | 使用方式和 spring 一致。 426 | 427 | ## 测试 428 | 429 | ```java 430 | @Autowired 431 | private UserService userService; 432 | 433 | @Test 434 | public void queryLogTest() { 435 | userService.query("spring-boot"); 436 | } 437 | ``` 438 | 439 | # 开源地址 440 | 441 | > Github: [https://github.com/houbb/auto-log](https://github.com/houbb/auto-log) 442 | 443 | > Gitee: [https://gitee.com/houbinbin/auto-log](https://gitee.com/houbinbin/auto-log) 444 | 445 | # Road-Map 446 | 447 | - [ ] distributed trace 448 | 449 | - [ ] 全局配置 比如全局的慢日志阈值设置等 参考 sandglass 中如何加载注解中的配置信息?(基于配置文件) 450 | 451 | - [x] 比例采样策略 452 | 453 | - [x] 自适应采样策略 454 | 455 | - [x] 改进 interceptor 拦截器,类似 dubbo filter 456 | 457 | - [x] 优化日志中的方法路径名称 458 | 459 | - [ ] 编译时注解特性 类似 aspectj 460 | 461 | - [ ] 基于 agent 特性,类似 sky-walking 462 | 463 | --------------------------------------------------- 464 | 465 | - [ ] 流程 466 | 467 | 日志/trace 信息的生成 468 | 469 | 采集 470 | 471 | 存储 472 | 473 | 检索/分析 474 | 475 | 可视化 476 | 477 | # 开源矩阵 478 | 479 | | 编号 | 名称 | 简介 | 标签 | 480 | |:----|:----|:----|:----| 481 | | 1 | [sensitive](https://github.com/houbb/sensitive) | 基于注解的日志脱敏框架,更加优雅的日志打印 | 工具,日志 | 482 | | 2 | [auto-log](https://github.com/houbb/auto-log) | 日志自动输出 | 工具,日志 | 483 | | 3 | [heaven](https://github.com/houbb/heaven) | 收集开发中常用的工具类 | 工具 | 484 | | 4 | [resubmit](https://github.com/houbb/resubmit) | 防止重复提交框架 | 工具 | 485 | | 5 | [validator](https://github.com/houbb/validator) | 新一代校验框架 | 工具 | 486 | | 6 | [rate-limit](https://github.com/houbb/rate-limit) | 渐进式限流工具框架 | 工具 | 487 | | 7 | [lock](https://github.com/houbb/lock) | 开箱即用分布式锁 | 工具 | 488 | | 8 | [lombok-ex](https://github.com/houbb/lombok-ex) | 编译时注解框架,扩展 lombok | 工具 | 489 | | 9 | [csv](https://github.com/houbb/csv) | CSV的读写工具 | 工具 | 490 | | 10 | [iexcel](https://github.com/houbb/iexcel) | EXCEL的读写工具,避免OOM | 工具 | 491 | | 11 | [leetcode](https://github.com/houbb/leetcode) | 力扣算法个人学习笔记 | 学习 | 492 | | 12 | [awesome-metaverse-zh](https://github.com/houbb/awesome-metaverse-zh) | 元宇宙精选 | 学习 | 493 | | 13 | [rpc](https://github.com/houbb/rpc) | 手写rpc框架 | 学习,中间件 | 494 | | 14 | [mybatis](https://github.com/houbb/mybatis) | 手写mybatis框架 | 学习,中间件 | 495 | | 15 | [cache](https://github.com/houbb/cache) | 手写redis框架 | 学习,中间件 | 496 | | 16 | [mq](https://github.com/houbb/mq) | 手写mq框架 | 学习,中间件 | 497 | | 17 | [ioc](https://github.com/houbb/ioc) | 手写spring ioc框架 | 学习,中间件 | 498 | | 18 | [async](https://github.com/houbb/async) | 手写线程池异步框架 | 学习,中间件 | 499 | | 19 | [jdbc-pool](https://github.com/houbb/jdbc-pool) | 手写数据库连接池实现 | 学习,中间件 | 500 | | 20 | [sisyphus](https://github.com/houbb/sisyphus) | 支持注解的重试框架 | 学习,中间件 | 501 | | 21 | [sandglass](https://github.com/houbb/sandglass) | 任务调度时间框架 | 学习,中间件 | 502 | | 22 | [segment](https://github.com/houbb/segment) | 基于结巴的分词实现 | NLP | 503 | | 23 | [pinyin](https://github.com/houbb/pinyin) | 高性能中文转拼音工具 | NLP | 504 | | 24 | [opencc4j](https://github.com/houbb/opencc4j) | 中文繁简体转换 | NLP | 505 | | 25 | [word-checker](https://github.com/houbb/word-checker) | 中英文拼写检测 | NLP | 506 | | 26 | [sensitive-word](https://github.com/houbb/sensitive-word) | 敏感词 | NLP | 507 | | 27 | [nlp-hanzi-similar](https://github.com/houbb/nlp-hanzi-similar) | 汉字相似度 | NLP | 508 | | 28 | [word-cloud](https://github.com/houbb/word-cloud) | 好用的词云工具 | DOC | 509 | | 29 | [markdown-toc](https://github.com/houbb/markdown-toc) | 为文档生成目录 | DOC | 510 | | 30 | [idoc](https://github.com/houbb/idoc) | 项目自动生成文档 | DOC | 511 | | 31 | [metadata](https://github.com/houbb/metadata) | 数据库元数据表文档生成 | DOC | 512 | | 32 | [data-factory](https://github.com/houbb/data-factory) | 测试自动生成对象信息 | TEST | 513 | | 33 | [junitperf](https://github.com/houbb/junitperf) | 性能测试框架,测试报告生成 | TEST | 514 | | 34 | [houbb.github.io](https://github.com/houbb/houbb.github.io) | 个人博客 | 学习 | 515 | -------------------------------------------------------------------------------- /auto-log-annotation/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | auto-log 7 | com.github.houbb 8 | 0.12.0 9 | 10 | 4.0.0 11 | 12 | auto-log-annotation 13 | 14 | 15 | 16 | com.github.houbb 17 | id-api 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /auto-log-annotation/src/main/java/com/github/houbb/auto/log/annotation/AutoLog.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.annotation; 2 | 3 | import com.github.houbb.auto.log.api.IAutoLogSampleCondition; 4 | import com.github.houbb.auto.log.api.IParamFilter; 5 | import com.github.houbb.id.api.Id; 6 | 7 | import java.lang.annotation.*; 8 | 9 | /** 10 | * 自动注解 11 | * 12 | * 考虑自定义输出的格式? 13 | * 14 | * slowMillsThreshold 1000 15 | * 16 | * 日志标识。 TraceId 17 | * 日志输出级别。(默认为 info) 18 | * 19 | * 异常能处理类,callback 后期拓展 20 | * 其他: 21 | * 输出信息 ip 等等。 22 | * 23 | * 不强依赖 spring 24 | * 可以 CGLIB OP Proxy 实现 25 | * 26 | * SPI 深入 27 | * 日志输出深入 ILog String 28 | * 29 | * ToString() 的实现策略。 30 | * 31 | * 添加方法描述参数。 32 | * 33 | * 34 | * 配置优先级:类注解 低于 方法注解 35 | * 36 | * @author binbin.hou 37 | * @since 0.0.1 38 | */ 39 | @Target({ElementType.METHOD, ElementType.TYPE}) 40 | @Retention(RetentionPolicy.RUNTIME) 41 | @Inherited 42 | public @interface AutoLog { 43 | 44 | /** 45 | * 是否启用 46 | * @return 结果 47 | * @since 0.0.10 48 | */ 49 | boolean enable() default true; 50 | 51 | /** 52 | * 输出参数 53 | * @return 参数 54 | * @since 0.0.1 55 | */ 56 | boolean param() default true; 57 | 58 | /** 59 | * 是否输出结果 60 | * @return 结果 61 | * @since 0.0.1 62 | */ 63 | boolean result() default true; 64 | 65 | /** 66 | * 是否输出时间 67 | * @return 耗时 68 | * @since 0.0.1 69 | */ 70 | boolean costTime() default true; 71 | 72 | /** 73 | * 是否输出异常信息 74 | * @return 是否 75 | * @since 0.0.6 76 | */ 77 | boolean exception() default true; 78 | 79 | /** 80 | * 慢日志阈值 81 | * 82 | * 当值小于 0 时,不进行慢日志统计。 83 | * 当值大于等于0时,当前值只要大于等于这个值,就进行统计。 84 | * @return 阈值 85 | * @since 0.0.4 86 | */ 87 | long slowThresholdMills() default -1; 88 | 89 | /** 90 | * 方法描述 91 | * @return 方法描述 92 | * @since 0.0.7 93 | */ 94 | String description() default ""; 95 | 96 | /** 97 | * trace id 策略 98 | * 99 | * TODO: id 全局策略考虑从配置文件中读取 100 | * 101 | * 直接废弃,直接以 auto-trace 的为准 102 | * 103 | * @return 结果 104 | * @since 0.0.16 105 | */ 106 | @Deprecated 107 | Class traceId() default Id.class; 108 | 109 | /** 110 | * 是否日志跟踪号,建议只在最外层启用即可。 111 | * 1. controller 112 | * 2. mq 113 | * 3. rpc 114 | * 115 | * 所有调用的最外层入口设置为 true 即可, service 层等底层实现设置为 false 116 | * 117 | * @return 结果 118 | * @since 0.0.16 119 | */ 120 | boolean enableTraceId() default false; 121 | 122 | /** 123 | * 采样条件 124 | * @return 采样 125 | * @since 0.5.0 126 | */ 127 | Class sampleCondition() default IAutoLogSampleCondition.class; 128 | 129 | /** 130 | * 采样值: 131 | * 132 | * 1. 当为 rate 采样时 0-100,只有当采样策略为随机的的时候才会生效。 133 | * @return 条件概率 134 | * @since 0.5.0 135 | */ 136 | int sampleRate() default 100; 137 | 138 | } 139 | -------------------------------------------------------------------------------- /auto-log-annotation/src/main/java/com/github/houbb/auto/log/api/IAutoLog.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.api; 2 | 3 | /** 4 | * @author binbin.hou 5 | * @since 0.0.7 6 | */ 7 | public interface IAutoLog { 8 | 9 | /** 10 | * 自动日志输出 11 | * @param context 上下文 12 | * @return 结果 13 | * @since 0.0.7 14 | * @throws Throwable 异常信息 15 | */ 16 | Object autoLog(IAutoLogContext context) throws Throwable; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /auto-log-annotation/src/main/java/com/github/houbb/auto/log/api/IAutoLogContext.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.api; 2 | 3 | import com.github.houbb.auto.log.annotation.AutoLog; 4 | 5 | import java.lang.reflect.Method; 6 | 7 | /** 8 | * 自动日志输出上下文 9 | * @author binbin.hou 10 | * @since 0.0.7 11 | */ 12 | public interface IAutoLogContext { 13 | 14 | /** 15 | * 注解信息 16 | * @return 注解信息 17 | * @since 0.0.7 18 | */ 19 | AutoLog autoLog(); 20 | 21 | /** 22 | * 参数信息 23 | * @return 参数信息 24 | * @since 0.0.7 25 | */ 26 | Object[] params(); 27 | 28 | /** 29 | * 方法信息 30 | * @return 方法信息 31 | * @since 0.0.7 32 | */ 33 | Method method(); 34 | 35 | /** 36 | * 方法执行 37 | * @return 执行 38 | * @since 0.0.7 39 | * @throws Throwable 异常信息 40 | */ 41 | Object process() throws Throwable; 42 | 43 | /** 44 | * 设置处理类 45 | * @param autoLogObjectHandler 处理类 46 | */ 47 | void autoLogObjectHandler(IAutoLogObjectHandler autoLogObjectHandler); 48 | 49 | /** 50 | * 获取处理类 51 | * @return 获取 52 | */ 53 | IAutoLogObjectHandler autoLogObjectHandler(); 54 | 55 | /** 56 | * 丢弃的大小限制 57 | */ 58 | int discardSizeLimit(); 59 | 60 | /** 61 | * 设置大小 62 | * @param discardSizeLimit 限制 63 | */ 64 | void discardSizeLimit(int discardSizeLimit); 65 | 66 | /** 67 | * 最长的日志长度 68 | * @since 0.11.0 69 | */ 70 | void maxLogLen(int len); 71 | 72 | /** 73 | * 最长的日志长度 74 | * @since 0.11.0 75 | */ 76 | int maxLogLen(); 77 | 78 | } 79 | -------------------------------------------------------------------------------- /auto-log-annotation/src/main/java/com/github/houbb/auto/log/api/IAutoLogObjectHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.api; 2 | 3 | /** 4 | * 对象处理器 5 | * @author binbin.hou 6 | * @since 0.10.0 7 | */ 8 | public interface IAutoLogObjectHandler { 9 | 10 | /** 11 | * 处理对象 12 | * @param rawObject 原始对象 13 | * @param context 上下文 14 | * @return 结果 15 | * @throws Exception 异常信息 16 | */ 17 | Object handle(Object rawObject, IAutoLogContext context) throws Exception; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /auto-log-annotation/src/main/java/com/github/houbb/auto/log/api/IAutoLogSampleCondition.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.api; 2 | 3 | /** 4 | * 采样条件 5 | * @author binbin.hou 6 | * @since 0.5.0 7 | */ 8 | public interface IAutoLogSampleCondition { 9 | 10 | /** 11 | * 条件 12 | * 13 | * @param context 上下文 14 | * @return 结果 15 | * @since 0.5.0 16 | */ 17 | boolean sampleCondition(IAutoLogContext context); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /auto-log-annotation/src/main/java/com/github/houbb/auto/log/api/IParamFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.api; 2 | 3 | /** 4 | * 参数过滤器接口 5 | * @author binbin.hou 6 | * @since 0.0.12 7 | */ 8 | public interface IParamFilter { 9 | 10 | /** 11 | * 入参过滤接口 12 | * @param context 上下文 13 | * @return 结果 14 | * @since 0.0.12 15 | */ 16 | Object[] filter(IParamFilterContext context); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /auto-log-annotation/src/main/java/com/github/houbb/auto/log/api/IParamFilterContext.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.api; 2 | 3 | /** 4 | * 入参过滤器上下文 5 | * @author binbin.hou 6 | * @since 0.0.12 7 | */ 8 | public interface IParamFilterContext { 9 | 10 | /** 11 | * 入参信息 12 | * @return 入参 13 | * @since 0.0.12 14 | */ 15 | Object[] params(); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /auto-log-annotation/src/main/java/com/github/houbb/auto/log/exception/AutoLogRuntimeException.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.exception; 2 | 3 | /** 4 | * @author binbin.hou 5 | * @since 0.0.10 6 | */ 7 | public class AutoLogRuntimeException extends RuntimeException { 8 | 9 | public AutoLogRuntimeException() { 10 | } 11 | 12 | public AutoLogRuntimeException(String message) { 13 | super(message); 14 | } 15 | 16 | public AutoLogRuntimeException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | 20 | public AutoLogRuntimeException(Throwable cause) { 21 | super(cause); 22 | } 23 | 24 | public AutoLogRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 25 | super(message, cause, enableSuppression, writableStackTrace); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /auto-log-core-extra/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.github.houbb 8 | auto-log 9 | 0.12.0 10 | 11 | 12 | auto-log-core-extra 13 | 14 | 15 | 8 16 | 8 17 | UTF-8 18 | 19 | 20 | -------------------------------------------------------------------------------- /auto-log-core-extra/src/main/java/org/springframework/core/io/InputStreamSource.java: -------------------------------------------------------------------------------- 1 | // 2 | // Source code recreated from a .class file by IntelliJ IDEA 3 | // (powered by FernFlower decompiler) 4 | // 5 | 6 | package org.springframework.core.io; 7 | 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | 11 | public interface InputStreamSource { 12 | InputStream getInputStream() throws IOException; 13 | } 14 | -------------------------------------------------------------------------------- /auto-log-core-extra/src/main/java/org/springframework/web/multipart/MultipartFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.web.multipart; 18 | 19 | import org.springframework.core.io.InputStreamSource; 20 | 21 | import java.io.File; 22 | import java.io.IOException; 23 | import java.io.InputStream; 24 | 25 | /** 26 | * A representation of an uploaded file received in a multipart request. 27 | * 28 | *

The file contents are either stored in memory or temporarily on disk. 29 | * In either case, the user is responsible for copying file contents to a 30 | * session-level or persistent store as and if desired. The temporary storage 31 | * will be cleared at the end of request processing. 32 | * 33 | * @author Juergen Hoeller 34 | * @author Trevor D. Cook 35 | * @since 29.09.2003 36 | */ 37 | public interface MultipartFile extends InputStreamSource { 38 | 39 | /** 40 | * Return the name of the parameter in the multipart form. 41 | * @return the name of the parameter (never {@code null} or empty) 42 | */ 43 | String getName(); 44 | 45 | /** 46 | * Return the original filename in the client's filesystem. 47 | *

This may contain path information depending on the browser used, 48 | * but it typically will not with any other than Opera. 49 | * @return the original filename, or the empty String if no file has been chosen 50 | * in the multipart form, or {@code null} if not defined or not available 51 | */ 52 | String getOriginalFilename(); 53 | 54 | /** 55 | * Return the content type of the file. 56 | * @return the content type, or {@code null} if not defined 57 | * (or no file has been chosen in the multipart form) 58 | */ 59 | String getContentType(); 60 | 61 | /** 62 | * Return whether the uploaded file is empty, that is, either no file has 63 | * been chosen in the multipart form or the chosen file has no content. 64 | * @return 是否为空 65 | */ 66 | boolean isEmpty(); 67 | 68 | /** 69 | * Return the size of the file in bytes. 70 | * @return the size of the file, or 0 if empty 71 | */ 72 | long getSize(); 73 | 74 | /** 75 | * Return the contents of the file as an array of bytes. 76 | * @return the contents of the file as bytes, or an empty byte array if empty 77 | * @throws IOException in case of access errors (if the temporary store fails) 78 | */ 79 | byte[] getBytes() throws IOException; 80 | 81 | /** 82 | * Return an InputStream to read the contents of the file from. 83 | *

The user is responsible for closing the returned stream. 84 | * @return the contents of the file as stream, or an empty stream if empty 85 | * @throws IOException in case of access errors (if the temporary store fails) 86 | */ 87 | @Override 88 | InputStream getInputStream() throws IOException; 89 | 90 | /** 91 | * Transfer the received file to the given destination file. 92 | *

This may either move the file in the filesystem, copy the file in the 93 | * filesystem, or save memory-held contents to the destination file. If the 94 | * destination file already exists, it will be deleted first. 95 | *

If the target file has been moved in the filesystem, this operation 96 | * cannot be invoked again afterwards. Therefore, call this method just once 97 | * in order to work with any storage mechanism. 98 | *

NOTE: Depending on the underlying provider, temporary storage 99 | * may be container-dependent, including the base directory for relative 100 | * destinations specified here (e.g. with Servlet 3.0 multipart handling). 101 | * For absolute destinations, the target file may get renamed/moved from its 102 | * temporary location or newly copied, even if a temporary copy already exists. 103 | * @param dest the destination file (typically absolute) 104 | * @throws IOException in case of reading or writing errors 105 | * @throws IllegalStateException if the file has already been moved 106 | * in the filesystem and is not available anymore for another transfer 107 | */ 108 | void transferTo(File dest) throws IOException, IllegalStateException; 109 | 110 | } 111 | -------------------------------------------------------------------------------- /auto-log-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | auto-log 7 | com.github.houbb 8 | 0.12.0 9 | 10 | 4.0.0 11 | 12 | auto-log-core 13 | 14 | 15 | 16 | 17 | com.github.houbb 18 | auto-log-annotation 19 | 20 | 21 | 22 | com.github.houbb 23 | auto-log-core-extra 24 | 25 | 26 | 27 | 28 | com.github.houbb 29 | heaven 30 | 31 | 32 | com.github.houbb 33 | log-integration 34 | 35 | 36 | com.github.houbb 37 | aop-core 38 | 39 | 40 | 41 | com.github.houbb 42 | id-core 43 | 44 | 45 | 46 | com.github.houbb 47 | common-filter 48 | 49 | 50 | 51 | com.github.houbb 52 | auto-trace-core 53 | 54 | 55 | 56 | com.github.houbb 57 | mybatis-interceptor 58 | 59 | 60 | 61 | 62 | com.alibaba 63 | fastjson 64 | 65 | 66 | 67 | javax.servlet 68 | javax.servlet-api 69 | 70 | 71 | 72 | org.apache.dubbo 73 | dubbo 74 | ${dubbo.version} 75 | provided 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/bs/AutoLogBs.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.bs; 2 | 3 | import com.github.houbb.auto.log.api.IAutoLog; 4 | import com.github.houbb.auto.log.api.IAutoLogContext; 5 | import com.github.houbb.auto.log.api.IAutoLogObjectHandler; 6 | import com.github.houbb.auto.log.core.core.impl.SimpleAutoLog; 7 | import com.github.houbb.auto.log.core.support.handler.AutoLogObjectHandlers; 8 | import com.github.houbb.heaven.util.common.ArgUtil; 9 | import com.github.houbb.heaven.util.lang.reflect.ClassUtil; 10 | import com.github.houbb.log.integration.core.Log; 11 | import com.github.houbb.log.integration.core.LogFactory; 12 | 13 | /** 14 | * @author binbin.hou 15 | * @since 0.0.2 16 | */ 17 | public final class AutoLogBs { 18 | 19 | private static final Log LOG = LogFactory.getLog(AutoLogBs.class); 20 | 21 | private AutoLogBs() { 22 | } 23 | 24 | /** 25 | * 上下文 26 | * @since 0.0.7 27 | */ 28 | private IAutoLogContext context; 29 | 30 | /** 31 | * 实现类 32 | * @since 0.0.7 33 | */ 34 | private IAutoLog autoLog = new SimpleAutoLog(); 35 | 36 | /** 37 | * @since 0.10.0 38 | */ 39 | private IAutoLogObjectHandler autoLogObjectHandler = AutoLogObjectHandlers.defaults(); 40 | 41 | /** 42 | * 丢弃的大小限制 43 | * @since 0.10.0 44 | */ 45 | private int discardSizeLimit = 1001; 46 | 47 | /** 48 | * 最长的日志长度 49 | * @since 0.11.0 50 | */ 51 | private int maxLogLen = 65535; 52 | 53 | /** 54 | * 新建对象实例 55 | * @return this 56 | * @since 0.0.3 57 | */ 58 | public static AutoLogBs newInstance() { 59 | return new AutoLogBs(); 60 | } 61 | 62 | public AutoLogBs discardSizeLimit(int discardSizeLimit) { 63 | this.discardSizeLimit = discardSizeLimit; 64 | return this; 65 | } 66 | 67 | public AutoLogBs autoLog(IAutoLog autoLog) { 68 | ArgUtil.notNull(autoLog, "autoLog"); 69 | 70 | this.autoLog = autoLog; 71 | return this; 72 | } 73 | 74 | public IAutoLogContext context() { 75 | return context; 76 | } 77 | 78 | public AutoLogBs context(IAutoLogContext context) { 79 | this.context = context; 80 | return this; 81 | } 82 | 83 | public AutoLogBs autoLogObjectHandler(IAutoLogObjectHandler autoLogObjectHandler) { 84 | ArgUtil.notNull(autoLogObjectHandler, "autoLogObjectHandler"); 85 | 86 | this.autoLogObjectHandler = autoLogObjectHandler; 87 | return this; 88 | } 89 | 90 | public AutoLogBs maxLogLen(int maxLogLen) { 91 | this.maxLogLen = maxLogLen; 92 | return this; 93 | } 94 | 95 | /** 96 | * 自定日志输出 97 | * @return 输出 98 | * @since 0.0.6 99 | * @throws Throwable 执行异常 100 | */ 101 | public Object execute() throws Throwable { 102 | context.autoLogObjectHandler(autoLogObjectHandler); 103 | context.discardSizeLimit(discardSizeLimit); 104 | context.maxLogLen(maxLogLen); 105 | return autoLog.autoLog(context); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/constant/AutoLogAttachmentKeyConst.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.constant; 2 | 3 | /** 4 | * 附加属性 5 | * 6 | * @since 0.4.0 7 | */ 8 | public class AutoLogAttachmentKeyConst { 9 | 10 | /** 11 | * 原始上下文 12 | */ 13 | public static final String AUTO_LOG_CONTEXT = "AUTO_LOG_CONTEXT"; 14 | 15 | /** 16 | * 开始时间 17 | */ 18 | public static final String AUTO_LOG_START_TIME = "AUTO_LOG_START_TIME"; 19 | 20 | /** 21 | * 过滤后的参数 22 | */ 23 | public static final String AUTO_LOG_FILTER_PARAMS = "AUTO_LOG_FILTER_PARAMS"; 24 | 25 | /** 26 | * 日志跟踪号 27 | */ 28 | public static final String AUTO_LOG_TRACE_ID = "AUTO_LOG_TRACE_ID"; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/core/impl/AbstractAutoLogContext.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.core.impl; 2 | 3 | import com.github.houbb.auto.log.annotation.AutoLog; 4 | import com.github.houbb.auto.log.api.IAutoLogContext; 5 | import com.github.houbb.auto.log.api.IAutoLogObjectHandler; 6 | 7 | import java.lang.reflect.Method; 8 | 9 | /** 10 | * 自动日志输出上下文 11 | * @author binbin.hou 12 | * @since 0.3.0 13 | */ 14 | public abstract class AbstractAutoLogContext implements IAutoLogContext { 15 | 16 | /** 17 | * 注解信息 18 | * @since 0.0.7 19 | */ 20 | private AutoLog autoLog; 21 | 22 | /** 23 | * 参数信息 24 | * @since 0.0.7 25 | */ 26 | private Object[] params; 27 | 28 | /** 29 | * 方法信息 30 | * @since 0.0.7 31 | */ 32 | private Method method; 33 | 34 | /** 35 | * 对象处理类 36 | */ 37 | private IAutoLogObjectHandler autoLogObjectHandler; 38 | 39 | /** 40 | * 丢弃的大小限制 41 | */ 42 | private int discardSizeLimit; 43 | 44 | /** 45 | * 最长的日志长度 46 | * @since 0.11.0 47 | */ 48 | private int maxLogLen = 65535; 49 | 50 | @Override 51 | public AutoLog autoLog() { 52 | return autoLog; 53 | } 54 | 55 | public AbstractAutoLogContext autoLog(AutoLog autoLog) { 56 | this.autoLog = autoLog; 57 | return this; 58 | } 59 | 60 | @Override 61 | public Object[] params() { 62 | return params; 63 | } 64 | 65 | public AbstractAutoLogContext params(Object[] params) { 66 | this.params = params; 67 | return this; 68 | } 69 | 70 | @Override 71 | public Method method() { 72 | return method; 73 | } 74 | 75 | public AbstractAutoLogContext method(Method method) { 76 | this.method = method; 77 | return this; 78 | } 79 | 80 | @Override 81 | public IAutoLogObjectHandler autoLogObjectHandler() { 82 | return autoLogObjectHandler; 83 | } 84 | 85 | @Override 86 | public void autoLogObjectHandler(IAutoLogObjectHandler autoLogObjectHandler) { 87 | this.autoLogObjectHandler = autoLogObjectHandler; 88 | } 89 | 90 | @Override 91 | public int discardSizeLimit() { 92 | return discardSizeLimit; 93 | } 94 | 95 | public void discardSizeLimit(int discardSizeLimit) { 96 | this.discardSizeLimit = discardSizeLimit; 97 | } 98 | 99 | @Override 100 | public int maxLogLen() { 101 | return maxLogLen; 102 | } 103 | 104 | @Override 105 | public void maxLogLen(int maxLogLen) { 106 | this.maxLogLen = maxLogLen; 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/core/impl/SimpleAutoLog.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.core.impl; 2 | 3 | import com.github.houbb.auto.log.api.IAutoLog; 4 | import com.github.houbb.auto.log.api.IAutoLogContext; 5 | import com.github.houbb.auto.log.api.IAutoLogObjectHandler; 6 | import com.github.houbb.auto.log.core.support.interceptor.chain.AutoLogFilterChainConst; 7 | import com.github.houbb.auto.log.core.support.interceptor.chain.AutoLogInvocation; 8 | import com.github.houbb.auto.log.core.support.interceptor.chain.AutoLogInvoker; 9 | import com.github.houbb.common.filter.api.Invoker; 10 | import com.github.houbb.common.filter.api.Result; 11 | import com.github.houbb.common.filter.support.invoke.InvokerChainBuilder; 12 | import com.github.houbb.heaven.util.util.ArrayUtil; 13 | 14 | /** 15 | * @author binbin.hou 16 | * @since 0.0.7 17 | */ 18 | public class SimpleAutoLog implements IAutoLog { 19 | 20 | /** 21 | * 自动日志输出 22 | * 23 | * @param context 上下文 24 | * @return 结果 25 | * @since 0.0.7 26 | */ 27 | @Override 28 | public Object autoLog(IAutoLogContext context) throws Throwable { 29 | //1. 基本信息 30 | final long startTimeMills = System.currentTimeMillis(); 31 | 32 | //2. 调用链设置 33 | AutoLogInvoker autoLogInvoker = new AutoLogInvoker(context); 34 | AutoLogInvocation invocation = new AutoLogInvocation(); 35 | invocation.setAutoLogContext(context); 36 | invocation.setRawParams(context.params()); 37 | invocation.setStartTime(startTimeMills); 38 | 39 | Invoker chainInvoker = InvokerChainBuilder.buildInvokerChain(autoLogInvoker, AutoLogFilterChainConst.GROUP); 40 | Result autoLogResult = chainInvoker.invoke(invocation); 41 | 42 | //3. 返回结果 43 | return autoLogResult.getValue(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/core/impl/SimpleAutoLogContext.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.core.impl; 2 | 3 | /** 4 | * 自动日志输出上下文 5 | * @author binbin.hou 6 | * @since 0.0.7 7 | */ 8 | public class SimpleAutoLogContext extends AbstractAutoLogContext { 9 | 10 | /** 11 | * 目标对象 12 | * @since 0.0.7 13 | */ 14 | private Object target; 15 | 16 | public static SimpleAutoLogContext newInstance() { 17 | return new SimpleAutoLogContext(); 18 | } 19 | 20 | public Object target() { 21 | return target; 22 | } 23 | 24 | public SimpleAutoLogContext target(Object target) { 25 | this.target = target; 26 | return this; 27 | } 28 | 29 | @Override 30 | public Object process() throws Exception { 31 | return super.method().invoke(target, super.params()); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/core/package-info.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.core; -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/exception/AutoLogException.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.exception; 2 | 3 | /** 4 | * @author d 5 | * @since 1.0.0 6 | */ 7 | public class AutoLogException extends RuntimeException { 8 | 9 | public AutoLogException() { 10 | } 11 | 12 | public AutoLogException(String message) { 13 | super(message); 14 | } 15 | 16 | public AutoLogException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | 20 | public AutoLogException(Throwable cause) { 21 | super(cause); 22 | } 23 | 24 | public AutoLogException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 25 | super(message, cause, enableSuppression, writableStackTrace); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/package-info.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core; -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/filter/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 过滤器 3 | * @author binbin.hou 4 | * @since 0.0.12 5 | */ 6 | package com.github.houbb.auto.log.core.support.filter; -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/filter/param/AbstractParamFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.filter.param; 2 | 3 | import com.github.houbb.auto.log.api.IParamFilter; 4 | import com.github.houbb.auto.log.api.IParamFilterContext; 5 | import com.github.houbb.heaven.util.util.ArrayUtil; 6 | 7 | /** 8 | * 抽象参数过滤器实现 9 | * @author binbin.hou 10 | * @since 0.0.12 11 | */ 12 | public abstract class AbstractParamFilter implements IParamFilter { 13 | 14 | /** 15 | * 执行参数过滤 16 | * @param params 入参 17 | * @return 结果 18 | * @since 0.0.12 19 | */ 20 | protected abstract Object[] doFilter(Object[] params); 21 | 22 | @Override 23 | public Object[] filter(IParamFilterContext context) { 24 | Object[] params = context.params(); 25 | return doFilter(params); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/filter/param/ParamFilterContext.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.filter.param; 2 | 3 | import com.github.houbb.auto.log.api.IParamFilterContext; 4 | 5 | /** 6 | * 上下文信息 7 | * @author binbin.hou 8 | * @since 0.0.12 9 | */ 10 | public class ParamFilterContext implements IParamFilterContext { 11 | 12 | /** 13 | * 参数信息 14 | * @since 0.0.12 15 | */ 16 | private Object[] params; 17 | 18 | public static ParamFilterContext newInstance() { 19 | return new ParamFilterContext(); 20 | } 21 | 22 | @Override 23 | public Object[] params() { 24 | return params; 25 | } 26 | 27 | public ParamFilterContext params(Object[] params) { 28 | this.params = params; 29 | return this; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/filter/param/WebParamFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.filter.param; 2 | 3 | import com.github.houbb.heaven.annotation.ThreadSafe; 4 | import com.github.houbb.heaven.util.lang.ObjectUtil; 5 | import com.github.houbb.heaven.util.util.ArrayUtil; 6 | import org.springframework.web.multipart.MultipartFile; 7 | 8 | import javax.servlet.ServletRequest; 9 | import javax.servlet.ServletResponse; 10 | 11 | /** 12 | * web 过滤器 13 | * 14 | * @author binbin.hou 15 | * @since 0.0.12 16 | */ 17 | @ThreadSafe 18 | public class WebParamFilter extends AbstractParamFilter { 19 | 20 | @Override 21 | protected Object[] doFilter(Object[] params) { 22 | if(ArrayUtil.isEmpty(params)) { 23 | return params; 24 | } 25 | 26 | Object[] filters = new Object[params.length]; 27 | for(int i = 0; i < params.length; i++) { 28 | Object param = params[i]; 29 | // 过滤掉特殊的入参 30 | if(ObjectUtil.isNotNull(param)) { 31 | if(param instanceof ServletRequest || 32 | param instanceof ServletResponse || 33 | param instanceof MultipartFile) { 34 | param = null; 35 | } 36 | } 37 | 38 | filters[i] = param; 39 | } 40 | 41 | return filters; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/handler/AbstractAutoLogObjectHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.handler; 2 | 3 | import com.github.houbb.auto.log.api.IAutoLogContext; 4 | import com.github.houbb.auto.log.api.IAutoLogObjectHandler; 5 | 6 | /** 7 | * @since 0.10.0 8 | */ 9 | public abstract class AbstractAutoLogObjectHandler implements IAutoLogObjectHandler { 10 | 11 | protected abstract Object doHandle(Object rawObject, IAutoLogContext context); 12 | 13 | @Override 14 | public Object handle(Object rawObject, IAutoLogContext context) throws Exception { 15 | if(rawObject == null) { 16 | return rawObject; 17 | } 18 | 19 | return doHandle(rawObject, context); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/handler/AutoLogObjectHandlerBigMemoryDiscard.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.handler; 2 | 3 | import com.github.houbb.auto.log.api.IAutoLogContext; 4 | import com.github.houbb.heaven.util.lang.ObjectUtil; 5 | import com.github.houbb.log.integration.core.Log; 6 | import com.github.houbb.log.integration.core.LogFactory; 7 | 8 | /** 9 | * 大对象丢弃 10 | * 11 | * @since 0.10.0 12 | */ 13 | public class AutoLogObjectHandlerBigMemoryDiscard extends AbstractAutoLogObjectHandler { 14 | 15 | private static final Log log = LogFactory.getLog(AutoLogObjectHandlerBigMemoryDiscard.class); 16 | 17 | @Override 18 | protected Object doHandle(Object rawObject, IAutoLogContext config) { 19 | // 对象大小 20 | int objectCollectionSize = ObjectUtil.getObjectCollectionSize(rawObject); 21 | 22 | // 执行丢弃 23 | final String className = rawObject.getClass().getName(); 24 | if(objectCollectionSize >= config.discardSizeLimit()) { 25 | log.warn("[AutoLog] Discard object with size {} >= limit {} className={}", objectCollectionSize, config.discardSizeLimit(), className); 26 | return null; 27 | } 28 | int maxFieldSize = ObjectUtil.getMaxFieldSize(rawObject); 29 | if(maxFieldSize >= config.discardSizeLimit()) { 30 | log.warn("[AutoLog] Discard object field with size {} >= limit {} className={}", maxFieldSize, config.discardSizeLimit(), className); 31 | return null; 32 | } 33 | 34 | return rawObject; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/handler/AutoLogObjectHandlerDubboResult.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.handler; 2 | 3 | import com.github.houbb.auto.log.api.IAutoLogContext; 4 | import org.springframework.web.multipart.MultipartFile; 5 | 6 | import javax.servlet.ServletRequest; 7 | import javax.servlet.ServletResponse; 8 | 9 | /** 10 | * dubbo 层的一些特殊对象 11 | * 12 | * @since 0.11.0 13 | */ 14 | public class AutoLogObjectHandlerDubboResult extends AbstractAutoLogObjectHandler { 15 | 16 | @Override 17 | protected Object doHandle(Object rawObject, IAutoLogContext context) { 18 | if(rawObject instanceof org.apache.dubbo.rpc.Result) { 19 | org.apache.dubbo.rpc.Result result = (org.apache.dubbo.rpc.Result) rawObject; 20 | return result.getValue(); 21 | } 22 | 23 | return rawObject; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/handler/AutoLogObjectHandlerInit.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.handler; 2 | 3 | import com.github.houbb.auto.log.api.IAutoLogContext; 4 | import com.github.houbb.auto.log.api.IAutoLogObjectHandler; 5 | import com.github.houbb.heaven.annotation.ThreadSafe; 6 | import com.github.houbb.heaven.support.pipeline.Pipeline; 7 | import com.github.houbb.heaven.support.pipeline.impl.DefaultPipeline; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * 初始化类 13 | * 14 | * @author binbin.hou 15 | * @since 0.0.13 16 | */ 17 | @ThreadSafe 18 | public abstract class AutoLogObjectHandlerInit implements IAutoLogObjectHandler { 19 | 20 | /** 21 | * 初始化列表 22 | * 23 | * @param pipeline 当前列表泳道 24 | * @since 0.0.13 25 | */ 26 | protected abstract void init(final Pipeline pipeline); 27 | 28 | @Override 29 | public Object handle(Object rawObject, IAutoLogContext context) throws Exception { 30 | Pipeline pipeline = new DefaultPipeline<>(); 31 | this.init(pipeline); 32 | 33 | Object handleResult = rawObject; 34 | 35 | List list = pipeline.list(); 36 | for (IAutoLogObjectHandler handler : list) { 37 | handleResult = handler.handle(handleResult, context); 38 | } 39 | 40 | return handleResult; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/handler/AutoLogObjectHandlerRaw.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.handler; 2 | 3 | import com.github.houbb.auto.log.api.IAutoLogContext; 4 | 5 | /** 6 | * 不做任何处理 7 | * 8 | * @since 0.10.0 9 | */ 10 | public class AutoLogObjectHandlerRaw extends AbstractAutoLogObjectHandler { 11 | 12 | @Override 13 | protected Object doHandle(Object rawObject, IAutoLogContext context) { 14 | return rawObject; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/handler/AutoLogObjectHandlerWebDiscard.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.handler; 2 | 3 | import com.github.houbb.auto.log.api.IAutoLogContext; 4 | import org.springframework.web.multipart.MultipartFile; 5 | 6 | import javax.servlet.ServletRequest; 7 | import javax.servlet.ServletResponse; 8 | 9 | /** 10 | * web 层的一些特殊对象 11 | * 12 | * @since 0.10.0 13 | */ 14 | public class AutoLogObjectHandlerWebDiscard extends AbstractAutoLogObjectHandler { 15 | 16 | @Override 17 | protected Object doHandle(Object rawObject, IAutoLogContext context) { 18 | if(rawObject instanceof ServletRequest || 19 | rawObject instanceof ServletResponse || 20 | rawObject instanceof MultipartFile) { 21 | return null; 22 | } 23 | 24 | return rawObject; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/handler/AutoLogObjectHandlers.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.handler; 2 | 3 | import com.github.houbb.auto.log.api.IAutoLogObjectHandler; 4 | import com.github.houbb.heaven.support.pipeline.Pipeline; 5 | import com.github.houbb.heaven.util.util.ArrayUtil; 6 | 7 | /** 8 | * 9 | * @since 0.11.0 10 | */ 11 | public class AutoLogObjectHandlers { 12 | 13 | /** 14 | * 责任链 15 | * @param objectHandler 对象处理 16 | * @param others 其他 17 | * @return 结果 18 | */ 19 | public static IAutoLogObjectHandler chains(final IAutoLogObjectHandler objectHandler, 20 | final IAutoLogObjectHandler... others) { 21 | return new AutoLogObjectHandlerInit() { 22 | @Override 23 | protected void init(Pipeline pipeline) { 24 | pipeline.addLast(objectHandler); 25 | 26 | if(ArrayUtil.isNotEmpty(others)) { 27 | for(IAutoLogObjectHandler other : others) { 28 | pipeline.addLast(other); 29 | } 30 | } 31 | } 32 | }; 33 | } 34 | 35 | /** 36 | * 默认策略 37 | * @return 策略 38 | */ 39 | public static IAutoLogObjectHandler defaults() { 40 | return chains(webDiscard(), dubboResult(), bigMemoryDiscard()); 41 | } 42 | 43 | /** 44 | * 原始对象 45 | * @return 原始 46 | */ 47 | public static IAutoLogObjectHandler raw() { 48 | return new AutoLogObjectHandlerRaw(); 49 | } 50 | 51 | /** 52 | * web 丢弃 53 | * @return 原始 54 | */ 55 | public static IAutoLogObjectHandler webDiscard() { 56 | return new AutoLogObjectHandlerWebDiscard(); 57 | } 58 | 59 | /** 60 | * 大对象 丢弃 61 | * @return 原始 62 | */ 63 | public static IAutoLogObjectHandler bigMemoryDiscard() { 64 | return new AutoLogObjectHandlerBigMemoryDiscard(); 65 | } 66 | 67 | /** 68 | * dubbo 结果 69 | * @return 原始 70 | * @since 0.11.0 71 | */ 72 | public static IAutoLogObjectHandler dubboResult() { 73 | return new AutoLogObjectHandlerDubboResult(); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/AutoLogMethodInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor; 2 | 3 | import com.github.houbb.aop.core.util.MethodInvocationUtil; 4 | import com.github.houbb.auto.log.annotation.AutoLog; 5 | import com.github.houbb.heaven.annotation.ThreadSafe; 6 | import com.github.houbb.heaven.util.lang.ObjectUtil; 7 | import com.github.houbb.log.integration.core.Log; 8 | import com.github.houbb.log.integration.core.LogFactory; 9 | import org.aopalliance.intercept.MethodInterceptor; 10 | import org.aopalliance.intercept.MethodInvocation; 11 | 12 | import java.lang.reflect.Method; 13 | import java.util.Arrays; 14 | 15 | /** 16 | * 1. 格式化可以自定义 17 | * 18 | * @author binbin.hou 19 | * @since 0.0.2 20 | */ 21 | @ThreadSafe 22 | @Deprecated 23 | public class AutoLogMethodInterceptor implements MethodInterceptor { 24 | 25 | private static final Log LOG = LogFactory.getLog(AutoLogMethodInterceptor.class); 26 | 27 | @Override 28 | public Object invoke(MethodInvocation methodInvocation) throws Throwable { 29 | String methodName = null; 30 | AutoLog autoLog = null; 31 | 32 | try { 33 | final long startMills = System.currentTimeMillis(); 34 | // 避免 AOP 时获取不到真正的实现 35 | Method method = MethodInvocationUtil.getActualMethod(methodInvocation); 36 | methodName = method.toString(); 37 | autoLog = method.getAnnotation(AutoLog.class); 38 | 39 | if (ObjectUtil.isNotNull(autoLog)) { 40 | //1. 是否输入入参 41 | if (autoLog.param()) { 42 | Object[] params = methodInvocation.getArguments(); 43 | LOG.info("{} param is {}.", methodName, Arrays.toString(params)); 44 | } 45 | } 46 | 47 | //2. 执行 48 | Object result = methodInvocation.proceed(); 49 | if (ObjectUtil.isNull(autoLog)) { 50 | return result; 51 | } 52 | 53 | //3. 结果 54 | if (autoLog.result()) { 55 | LOG.info("{} result is {}.", methodName, result); 56 | } 57 | //3.1 耗时 58 | final long slowThreshold = autoLog.slowThresholdMills(); 59 | if (autoLog.costTime() || slowThreshold >= 0) { 60 | final long endMills = System.currentTimeMillis(); 61 | long costTime = endMills - startMills; 62 | if (autoLog.costTime()) { 63 | LOG.info("{} cost time is {}ms.", methodName, costTime); 64 | } 65 | 66 | //3.2 慢日志 67 | if (slowThreshold >= 0 && costTime >= slowThreshold) { 68 | LOG.warn("{} is slow log, {}ms >= {}ms.", methodName, costTime, slowThreshold); 69 | } 70 | } 71 | 72 | return result; 73 | } catch (Throwable throwable) { 74 | if (ObjectUtil.isNotNull(autoLog)) { 75 | LOG.error("{} meet ex.", methodName, throwable); 76 | } 77 | // re throw 78 | throw throwable; 79 | } 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/cache/AutoLogCacheInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor.cache; 2 | 3 | import com.github.houbb.auto.log.core.support.interceptor.common.AbstractAutoLogCommonFilter; 4 | import com.github.houbb.common.cache.core.constant.CommonCacheConst; 5 | import com.github.houbb.common.filter.annotation.FilterActive; 6 | 7 | @FilterActive(group = CommonCacheConst.COMMON_CACHE_GROUP, order = CommonCacheConst.COMMON_CACHE_ORDER + 1) 8 | public class AutoLogCacheInterceptor extends AbstractAutoLogCommonFilter { 9 | } 10 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/chain/AutoLogCommonFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor.chain; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.github.houbb.auto.log.annotation.AutoLog; 5 | import com.github.houbb.auto.log.api.IAutoLogContext; 6 | import com.github.houbb.auto.log.api.IAutoLogObjectHandler; 7 | import com.github.houbb.auto.log.api.IAutoLogSampleCondition; 8 | import com.github.houbb.auto.log.core.constant.AutoLogAttachmentKeyConst; 9 | import com.github.houbb.auto.log.core.support.sample.AutoLogSampleConditionAdaptive; 10 | import com.github.houbb.auto.log.core.support.sample.AutoLogSampleConditionRate; 11 | import com.github.houbb.auto.log.core.support.sample.AutoLogSampleConditions; 12 | import com.github.houbb.common.filter.annotation.FilterActive; 13 | import com.github.houbb.common.filter.api.CommonFilter; 14 | import com.github.houbb.common.filter.api.Invocation; 15 | import com.github.houbb.common.filter.api.Invoker; 16 | import com.github.houbb.common.filter.api.Result; 17 | import com.github.houbb.common.filter.exception.CommonFilterException; 18 | import com.github.houbb.heaven.util.lang.StringUtil; 19 | import com.github.houbb.heaven.util.lang.reflect.ClassUtil; 20 | import com.github.houbb.heaven.util.lang.reflect.ReflectMethodUtil; 21 | import com.github.houbb.heaven.util.util.ArrayUtil; 22 | import com.github.houbb.id.api.Id; 23 | import com.github.houbb.id.core.core.Ids; 24 | import com.github.houbb.id.core.util.IdThreadLocalHelper; 25 | import com.github.houbb.log.integration.core.Log; 26 | import com.github.houbb.log.integration.core.LogFactory; 27 | 28 | import java.lang.reflect.Method; 29 | import java.util.Arrays; 30 | 31 | /** 32 | * 默认的日志拦截器 33 | */ 34 | @FilterActive(order = AutoLogFilterChainConst.ORDER, group = AutoLogFilterChainConst.GROUP) 35 | public class AutoLogCommonFilter implements CommonFilter { 36 | 37 | private static final Log LOG = LogFactory.getLog(AutoLogCommonFilter.class); 38 | 39 | /** 40 | * 是否需要处理日志自动输出 41 | * 42 | * @param autoLog 上下文 43 | * @return 结果 44 | * @since 0.0.10 45 | */ 46 | protected boolean enableAutoLog(final AutoLog autoLog) { 47 | if (autoLog == null) { 48 | return false; 49 | } 50 | 51 | return autoLog.enable(); 52 | } 53 | 54 | /** 55 | * 获取方法描述 56 | * 57 | * @param method 方法 58 | * @param autoLog 注解 59 | * @return 结果 60 | * @since 0.0.10 61 | */ 62 | protected String getMethodDescription(Method method, AutoLog autoLog) { 63 | String methodName = ""; 64 | 65 | if (autoLog != null 66 | && StringUtil.isNotEmpty(autoLog.description())) { 67 | methodName = autoLog.description(); 68 | } else { 69 | methodName = ReflectMethodUtil.getMethodFullName(method); 70 | } 71 | 72 | return methodName; 73 | } 74 | 75 | /** 76 | * 获取 traceId 77 | * 78 | * @param autoLog 日志注解 79 | * @return 结果 80 | * @since 0.0.10 81 | */ 82 | protected String getTraceId(AutoLog autoLog) { 83 | //1. 优先看当前线程中是否存在 84 | String oldId = IdThreadLocalHelper.get(); 85 | if (StringUtil.isNotEmpty(oldId)) { 86 | return formatTraceId(oldId); 87 | } 88 | 89 | //2. 返回对应的标识 90 | Id id = getActualTraceId(autoLog); 91 | return formatTraceId(id.id()); 92 | } 93 | 94 | /** 95 | * 获取日志跟踪号策略 96 | * 97 | * @param autoLog 注解 98 | * @return 没结果 99 | */ 100 | protected Id getActualTraceId(AutoLog autoLog) { 101 | Class idClass = autoLog.traceId(); 102 | if (Id.class.equals(idClass)) { 103 | return Ids.uuid32(); 104 | } 105 | return ClassUtil.newInstance(autoLog.traceId()); 106 | } 107 | 108 | /** 109 | * 格式化日志跟踪号 110 | * 111 | * @param id 跟踪号 112 | * @return 结果 113 | * @since 0.0.16 114 | */ 115 | protected String formatTraceId(String id) { 116 | return String.format("[%s] ", id); 117 | } 118 | 119 | @Override 120 | public Result invoke(Invoker invoker, Invocation invocation) throws CommonFilterException { 121 | final AutoLogInvocation autoLogInvocation = (AutoLogInvocation) invocation; 122 | final IAutoLogContext autoLogContext = autoLogInvocation.getAutoLogContext(); 123 | final AutoLog autoLog = autoLogContext.autoLog(); 124 | final boolean enableAutoLog = enableAutoLog(autoLog); 125 | if (!enableAutoLog) { 126 | return invoker.invoke(invocation); 127 | } 128 | 129 | final String description = getMethodDescription(autoLogContext.method(), autoLog); 130 | // 默认从上下文中取一次 131 | String traceId = IdThreadLocalHelper.get(); 132 | try { 133 | // 设置 traceId 策略 134 | if (autoLog.enableTraceId()) { 135 | Id id = getActualTraceId(autoLog); 136 | traceId = id.id(); 137 | 138 | invocation.setAttachment(AutoLogAttachmentKeyConst.AUTO_LOG_TRACE_ID, traceId); 139 | IdThreadLocalHelper.put(traceId); 140 | } 141 | 142 | Result result = invoker.invoke(invocation); 143 | 144 | // 日志增强 145 | logForEnhance(autoLogContext, traceId, description, result.getValue(), invocation); 146 | 147 | return result; 148 | } catch (Exception e) { 149 | if (autoLog.exception()) { 150 | String message = String.format("[TID=%s][EXCEPTION=%s]", traceId, e.getMessage()); 151 | LOG.error(message, e); 152 | } 153 | 154 | throw new RuntimeException(e); 155 | } 156 | } 157 | 158 | /** 159 | * 计算采样条件 160 | * 161 | * @param autoLogContext 上下文 162 | * @param traceId 日志跟踪号 163 | * @param description 方法描述 164 | * @param resultValue 返回值 165 | * @param invocation 调用上下文 166 | * @return 是否 167 | * @since 0.5.0 168 | */ 169 | private boolean calcSampleCondition(final IAutoLogContext autoLogContext, 170 | final String traceId, 171 | final String description, 172 | final Object resultValue, 173 | Invocation invocation) { 174 | final AutoLog autoLog = autoLogContext.autoLog(); 175 | if (autoLog == null) { 176 | //TODO: 默认实现策略 177 | 178 | return true; 179 | } 180 | 181 | Class sampleConditionClass = autoLog.sampleCondition(); 182 | 183 | // 默认 184 | if (sampleConditionClass.equals(IAutoLogSampleCondition.class)) { 185 | return true; 186 | } 187 | 188 | // 如果是概率 189 | if (sampleConditionClass.equals(AutoLogSampleConditionRate.class)) { 190 | int sampleRate = autoLog.sampleRate(); 191 | return AutoLogSampleConditions.rate(sampleRate).sampleCondition(autoLogContext); 192 | } else if (sampleConditionClass.equals(AutoLogSampleConditionAdaptive.class)) { 193 | // 自适应 194 | AutoLogSampleConditionAdaptive adaptive = AutoLogSampleConditionAdaptive.getInstance(); 195 | return adaptive.sampleCondition(autoLogContext); 196 | } 197 | 198 | // 其他 199 | IAutoLogSampleCondition sampleCondition = ClassUtil.newInstance(sampleConditionClass); 200 | return sampleCondition.sampleCondition(autoLogContext); 201 | } 202 | 203 | /** 204 | * 增强日志输出 205 | * 206 | * @param autoLogContext 上下文 207 | * @param traceId 日志跟踪号 208 | * @param description 方法描述 209 | * @param resultValue 返回值 210 | * @param invocation 调用上下文 211 | */ 212 | private void logForEnhance(final IAutoLogContext autoLogContext, 213 | final String traceId, 214 | final String description, 215 | final Object resultValue, 216 | Invocation invocation) { 217 | final AutoLogInvocation autoLogInvocation = (AutoLogInvocation) invocation; 218 | 219 | // 采样条件 220 | boolean condition = calcSampleCondition(autoLogContext, traceId, description, resultValue, invocation); 221 | if (!condition) { 222 | return; 223 | } 224 | 225 | final AutoLog autoLog = autoLogContext.autoLog(); 226 | 227 | StringBuilder logBuilder = new StringBuilder(); 228 | logBuilder.append(String.format("[TID=%s]", traceId)); 229 | logBuilder.append(String.format("[METHOD=%s]", description)); 230 | 231 | // 入参 232 | if (autoLog.param()) { 233 | // 构建 params 234 | logBuilder.append(String.format("[PARAM=%s]", getParamsString(autoLogContext))); 235 | } 236 | // 出参 237 | if (autoLog.result()) { 238 | logBuilder.append(String.format("[RESULT=%s]", getResultString(autoLogContext, resultValue))); 239 | } 240 | // 耗时 241 | //3.1 耗时 & 慢日志 242 | if (autoLog.costTime()) { 243 | long startTime = autoLogInvocation.getStartTime(); 244 | long costTime = System.currentTimeMillis() - startTime; 245 | logBuilder.append(String.format("[COST=%d ms]", costTime)); 246 | 247 | // 慢日志 248 | final long slowThreshold = autoLog.slowThresholdMills(); 249 | if (slowThreshold > 0 && costTime > slowThreshold) { 250 | logBuilder.append(String.format("[SLOW-THRESHOLD=%s]", slowThreshold)); 251 | } 252 | } 253 | 254 | // 输出日志 255 | LOG.info(logBuilder.toString()); 256 | } 257 | 258 | /** 259 | * 获取过滤的参数 260 | * 261 | * @param context 上下文 262 | * @return 结果 263 | * @throws Exception 异常 264 | * @since 0.11.0 265 | */ 266 | protected Object[] getFilterParams(IAutoLogContext context) throws Exception { 267 | Object[] params = context.params(); 268 | 269 | if (ArrayUtil.isEmpty(params)) { 270 | return params; 271 | } 272 | // 直接丢弃整体 273 | if (params.length > context.discardSizeLimit()) { 274 | return null; 275 | } 276 | 277 | Object[] filters = new Object[params.length]; 278 | final IAutoLogObjectHandler autoLogObjectHandler = context.autoLogObjectHandler(); 279 | for (int i = 0; i < params.length; i++) { 280 | Object param = params[i]; 281 | 282 | Object filterParam = autoLogObjectHandler.handle(param, context); 283 | 284 | filters[i] = filterParam; 285 | } 286 | 287 | return filters; 288 | } 289 | 290 | /** 291 | * 根据限制截断 292 | * @param text 文本 293 | * @param context 上下文 294 | * @return 结果 295 | */ 296 | protected String subTextByLimit(String text, IAutoLogContext context) { 297 | if(StringUtil.isEmpty(text)) { 298 | return text; 299 | } 300 | 301 | // 长度 302 | int maxLogLen = context.maxLogLen(); 303 | int len = text.length(); 304 | if(len > maxLogLen) { 305 | return text.substring(0, maxLogLen) + "超长截断" + len; 306 | } 307 | return text; 308 | } 309 | 310 | /** 311 | * 获取参数字符串 312 | * 313 | * @param context 入参 314 | * @return 结果 315 | */ 316 | protected String getParamsString(IAutoLogContext context) { 317 | String result = ""; 318 | try { 319 | Object[] params = getFilterParams(context); 320 | 321 | try { 322 | result = JSON.toJSONString(params); 323 | } catch (Exception e) { 324 | result = Arrays.toString(params); 325 | } 326 | 327 | // 截断 328 | return subTextByLimit(result, context); 329 | } catch (Exception exception) { 330 | LOG.error("getParamsString meet ex [context={}]", context, exception); 331 | return ""; 332 | } 333 | } 334 | 335 | /** 336 | * 获取结果字符串 337 | * 338 | * @param context 上下文 339 | * @param rawValue 结果 340 | * @return 结果 341 | */ 342 | protected String getResultString(IAutoLogContext context, 343 | Object rawValue) { 344 | String text = ""; 345 | try { 346 | Object result = getFilterResult(context, rawValue); 347 | try { 348 | text = JSON.toJSONString(result); 349 | } catch (Exception e) { 350 | text = result.toString(); 351 | } 352 | 353 | return subTextByLimit(text, context); 354 | } catch (Exception exception) { 355 | LOG.error("getResultString meet ex [context={}][result={}]", context, rawValue, exception); 356 | 357 | return ""; 358 | } 359 | } 360 | 361 | /** 362 | * 获取真正的结果 363 | * 364 | * @param context 上下文 365 | * @param resultVal 结果值 366 | * @return 结构 367 | * @since 0.11.0 368 | */ 369 | protected Object getFilterResult(IAutoLogContext context, 370 | Object resultVal) throws Exception { 371 | return context.autoLogObjectHandler().handle(resultVal, context); 372 | } 373 | 374 | } 375 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/chain/AutoLogFilterChainConst.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor.chain; 2 | 3 | /** 4 | * @author d 5 | * @since 1.0.0 6 | */ 7 | public class AutoLogFilterChainConst { 8 | 9 | public static final int ORDER = 1001; 10 | 11 | public static final String GROUP = "auto-log-group"; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/chain/AutoLogInvocation.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor.chain; 2 | 3 | import com.github.houbb.auto.log.api.IAutoLogContext; 4 | import com.github.houbb.common.filter.support.invocation.CommonInvocation; 5 | 6 | /** 7 | * 日志 invocation 8 | * @since 0.7.0 9 | */ 10 | public class AutoLogInvocation extends CommonInvocation { 11 | 12 | private IAutoLogContext autoLogContext; 13 | 14 | private long startTime; 15 | 16 | /** 17 | * 原始的入参 18 | */ 19 | private Object[] rawParams; 20 | 21 | public IAutoLogContext getAutoLogContext() { 22 | return autoLogContext; 23 | } 24 | 25 | public void setAutoLogContext(IAutoLogContext autoLogContext) { 26 | this.autoLogContext = autoLogContext; 27 | } 28 | 29 | public long getStartTime() { 30 | return startTime; 31 | } 32 | 33 | public void setStartTime(long startTime) { 34 | this.startTime = startTime; 35 | } 36 | 37 | public Object[] getRawParams() { 38 | return rawParams; 39 | } 40 | 41 | public void setRawParams(Object[] rawParams) { 42 | this.rawParams = rawParams; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/chain/AutoLogInvoker.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor.chain; 2 | 3 | import com.github.houbb.auto.log.api.IAutoLogContext; 4 | import com.github.houbb.common.filter.api.Invocation; 5 | import com.github.houbb.common.filter.api.Invoker; 6 | import com.github.houbb.common.filter.api.Result; 7 | import com.github.houbb.common.filter.exception.CommonFilterException; 8 | import com.github.houbb.common.filter.support.result.CommonResult; 9 | 10 | /** 11 | * 默认的 invoker 12 | * 13 | * @since 0.4.0 14 | */ 15 | public class AutoLogInvoker implements Invoker { 16 | 17 | private final IAutoLogContext context; 18 | 19 | public AutoLogInvoker(IAutoLogContext context) { 20 | this.context = context; 21 | } 22 | 23 | @Override 24 | public Result invoke(Invocation invocation) throws CommonFilterException { 25 | Result result = new CommonResult(); 26 | try { 27 | Object resultValue = context.process(); 28 | result.setValue(resultValue); 29 | } catch (Throwable e) { 30 | result.setException(e); 31 | throw new RuntimeException(e); 32 | } 33 | 34 | return result; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/common/AbstractAutoLogCommonFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor.common; 2 | 3 | import com.github.houbb.auto.log.annotation.AutoLog; 4 | import com.github.houbb.auto.log.core.bs.AutoLogBs; 5 | import com.github.houbb.auto.log.core.exception.AutoLogException; 6 | import com.github.houbb.common.filter.api.CommonFilter; 7 | import com.github.houbb.common.filter.api.Invocation; 8 | import com.github.houbb.common.filter.api.Invoker; 9 | import com.github.houbb.common.filter.api.Result; 10 | import com.github.houbb.common.filter.exception.CommonFilterException; 11 | import com.github.houbb.heaven.annotation.CommonEager; 12 | 13 | import java.lang.annotation.Annotation; 14 | import java.lang.reflect.Field; 15 | import java.lang.reflect.InvocationHandler; 16 | import java.lang.reflect.Proxy; 17 | import java.util.Map; 18 | 19 | /** 20 | * 通用的抽象实现 21 | * 22 | * @since 1.0.0 23 | */ 24 | public class AbstractAutoLogCommonFilter implements CommonFilter { 25 | 26 | protected String buildMethodName(Invoker invoker, 27 | Invocation invocation) { 28 | return ""; 29 | } 30 | 31 | protected AutoLog buildAutoLog(Invoker invoker, 32 | Invocation invocation) { 33 | AutoLog autoLog = AutoLogCommonGlobalAnnotation.class.getAnnotation(AutoLog.class); 34 | String methodName = buildMethodName(invoker, invocation); 35 | updateAnnotationValue(autoLog, "description", methodName); 36 | 37 | return autoLog; 38 | } 39 | 40 | @Override 41 | public Result invoke(Invoker invoker, 42 | Invocation invocation) 43 | throws CommonFilterException { 44 | AutoLogCommonFilterContext context = new AutoLogCommonFilterContext(); 45 | context.setInvocation(invocation); 46 | context.setInvoker(invoker); 47 | 48 | AutoLog autoLog = buildAutoLog(invoker, invocation); 49 | 50 | context.autoLog(autoLog); 51 | 52 | try { 53 | return (Result) AutoLogBs.newInstance() 54 | .context(context) 55 | .execute(); 56 | } catch (Throwable throwable) { 57 | throw new AutoLogException(throwable); 58 | } 59 | } 60 | 61 | /** 62 | * 更新注解的值 63 | * @param annotation 注解 64 | * @param annotationKey 键 65 | * @param value 值 66 | */ 67 | @CommonEager 68 | protected void updateAnnotationValue(Annotation annotation, 69 | String annotationKey, 70 | Object value) { 71 | if(annotation != null) { 72 | try { 73 | InvocationHandler h = Proxy.getInvocationHandler(annotation); 74 | Field hField = h.getClass().getDeclaredField("memberValues"); 75 | hField.setAccessible(true); 76 | Map memberMethods = (Map) hField.get(h); 77 | memberMethods.put(annotationKey, value); 78 | } catch (NoSuchFieldException | IllegalAccessException e) { 79 | throw new RuntimeException(e); 80 | } 81 | } 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/common/AutoLogCommonFilterContext.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor.common; 2 | 3 | import com.github.houbb.auto.log.core.core.impl.AbstractAutoLogContext; 4 | import com.github.houbb.common.filter.api.Invocation; 5 | import com.github.houbb.common.filter.api.Invoker; 6 | 7 | /** 8 | * 通用的调用上下文 9 | * 10 | * @author d 11 | * @since 1.0.0 12 | */ 13 | public class AutoLogCommonFilterContext extends AbstractAutoLogContext { 14 | 15 | private Invoker invoker; 16 | 17 | private Invocation invocation; 18 | 19 | public Invoker getInvoker() { 20 | return invoker; 21 | } 22 | 23 | public void setInvoker(Invoker invoker) { 24 | this.invoker = invoker; 25 | } 26 | 27 | public Invocation getInvocation() { 28 | return invocation; 29 | } 30 | 31 | public void setInvocation(Invocation invocation) { 32 | this.invocation = invocation; 33 | } 34 | 35 | @Override 36 | public Object process() throws Throwable { 37 | return invoker.invoke(invocation); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/common/AutoLogCommonGlobalAnnotation.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor.common; 2 | 3 | import com.github.houbb.auto.log.annotation.AutoLog; 4 | 5 | /** 6 | * 默认的全局配置 7 | * 8 | * @author d 9 | * @since 1.0.0 10 | */ 11 | @AutoLog 12 | public class AutoLogCommonGlobalAnnotation { 13 | } 14 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/dubbo/AbstractAutoLogDubboFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor.dubbo; 2 | 3 | import com.github.houbb.auto.log.annotation.AutoLog; 4 | import com.github.houbb.auto.log.core.bs.AutoLogBs; 5 | import com.github.houbb.auto.log.core.support.interceptor.common.AutoLogCommonGlobalAnnotation; 6 | import com.github.houbb.heaven.annotation.CommonEager; 7 | import org.apache.dubbo.rpc.*; 8 | 9 | import java.lang.annotation.Annotation; 10 | import java.lang.reflect.Field; 11 | import java.lang.reflect.InvocationHandler; 12 | import java.lang.reflect.Proxy; 13 | import java.util.Map; 14 | 15 | /** 16 | * 通用的抽象实现 17 | * 18 | * @since 1.0.0 19 | */ 20 | public abstract class AbstractAutoLogDubboFilter implements Filter { 21 | 22 | protected String buildMethodName(Invoker invoker, Invocation invocation) { 23 | return invocation.getTargetServiceUniqueName() + "#" + invocation.getMethodName(); 24 | } 25 | 26 | @Override 27 | public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { 28 | AutoLogDubboContext context = new AutoLogDubboContext(); 29 | context.setInvoker(invoker); 30 | context.setInvocation(invocation); 31 | context.params(invocation.getArguments()); 32 | 33 | // 其他属性 34 | AutoLog autoLog = AutoLogCommonGlobalAnnotation.class.getAnnotation(AutoLog.class); 35 | String methodName = buildMethodName(invoker, invocation); 36 | updateAnnotationValue(autoLog, "description", methodName); 37 | context.autoLog(autoLog); 38 | //Method 可以暂时不处理 39 | 40 | try { 41 | return (Result) AutoLogBs.newInstance() 42 | .context(context) 43 | .execute(); 44 | } catch (Throwable e) { 45 | throw new RpcException(e); 46 | } 47 | } 48 | 49 | /** 50 | * 更新注解的值 51 | * @param annotation 注解 52 | * @param annotationKey 键 53 | * @param value 值 54 | */ 55 | @CommonEager 56 | private void updateAnnotationValue(Annotation annotation, 57 | String annotationKey, 58 | Object value) { 59 | if(annotation != null) { 60 | try { 61 | InvocationHandler h = Proxy.getInvocationHandler(annotation); 62 | Field hField = h.getClass().getDeclaredField("memberValues"); 63 | hField.setAccessible(true); 64 | Map memberMethods = (Map) hField.get(h); 65 | memberMethods.put(annotationKey, value); 66 | } catch (NoSuchFieldException | IllegalAccessException e) { 67 | throw new RuntimeException(e); 68 | } 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/dubbo/AutoLogDubboConsumerFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor.dubbo; 2 | 3 | import com.github.houbb.auto.trace.constants.AutoTraceDubboConst; 4 | import org.apache.dubbo.common.constants.CommonConstants; 5 | import org.apache.dubbo.common.extension.Activate; 6 | 7 | /** 8 | * 消费者-客户端 9 | * @since 0.10.0 10 | */ 11 | @Activate(group = CommonConstants.CONSUMER, order = AutoTraceDubboConst.CONSUMER_ORDER + 1) 12 | public class AutoLogDubboConsumerFilter extends AbstractAutoLogDubboFilter { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/dubbo/AutoLogDubboContext.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor.dubbo; 2 | 3 | import com.github.houbb.auto.log.core.core.impl.AbstractAutoLogContext; 4 | import org.apache.dubbo.rpc.Invocation; 5 | import org.apache.dubbo.rpc.Invoker; 6 | 7 | /** 8 | * 通用的调用上下文 9 | * 10 | * @author d 11 | * @since 1.0.0 12 | */ 13 | public class AutoLogDubboContext extends AbstractAutoLogContext { 14 | 15 | private Invoker invoker; 16 | 17 | private Invocation invocation; 18 | 19 | public Invoker getInvoker() { 20 | return invoker; 21 | } 22 | 23 | public void setInvoker(Invoker invoker) { 24 | this.invoker = invoker; 25 | } 26 | 27 | public Invocation getInvocation() { 28 | return invocation; 29 | } 30 | 31 | public void setInvocation(Invocation invocation) { 32 | this.invocation = invocation; 33 | } 34 | 35 | @Override 36 | public Object process() throws Throwable { 37 | return invoker.invoke(invocation); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/dubbo/AutoLogDubboProviderFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor.dubbo; 2 | 3 | 4 | import com.github.houbb.auto.trace.constants.AutoTraceDubboConst; 5 | import org.apache.dubbo.common.constants.CommonConstants; 6 | import org.apache.dubbo.common.extension.Activate; 7 | 8 | /** 9 | * @since 1.0.0 10 | */ 11 | @Activate(group = CommonConstants.PROVIDER, order = AutoTraceDubboConst.PROVIDER_ORDER + 1) 12 | public class AutoLogDubboProviderFilter extends AbstractAutoLogDubboFilter { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/jms/AutoLogJmsConsumerInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor.jms; 2 | 3 | import com.github.houbb.auto.log.core.support.interceptor.common.AbstractAutoLogCommonFilter; 4 | import com.github.houbb.auto.trace.constants.SpanTypeEnum; 5 | import com.github.houbb.auto.trace.constants.TraceTypeEnum; 6 | import com.github.houbb.auto.trace.interceptor.AbstractAutoTraceProxyInterceptor; 7 | import com.github.houbb.common.filter.annotation.FilterActive; 8 | import com.github.houbb.common.filter.api.Invoker; 9 | import com.github.houbb.common.jms.core.constant.CommonJmsConst; 10 | import com.github.houbb.common.proxy.core.core.impl.CommonProxyInvocation; 11 | 12 | /** 13 | * jms 消费者 14 | */ 15 | @FilterActive(group = CommonJmsConst.GROUP_CONSUMER, order = CommonJmsConst.ORDER_CONSUMER + 1) 16 | public class AutoLogJmsConsumerInterceptor extends AbstractAutoLogCommonFilter { 17 | } 18 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/jms/AutoLogJmsProducerInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor.jms; 2 | 3 | import com.github.houbb.auto.log.core.support.interceptor.common.AbstractAutoLogCommonFilter; 4 | import com.github.houbb.auto.trace.constants.SpanTypeEnum; 5 | import com.github.houbb.auto.trace.constants.TraceTypeEnum; 6 | import com.github.houbb.auto.trace.interceptor.AbstractAutoTraceProxyInterceptor; 7 | import com.github.houbb.common.filter.annotation.FilterActive; 8 | import com.github.houbb.common.filter.api.Invoker; 9 | import com.github.houbb.common.jms.core.constant.CommonJmsConst; 10 | import com.github.houbb.common.proxy.core.core.impl.CommonProxyInvocation; 11 | 12 | /** 13 | * jms 生产者 14 | */ 15 | @FilterActive(group = CommonJmsConst.GROUP_PRODUCER, order = CommonJmsConst.ORDER_PRODUCER + 1) 16 | public class AutoLogJmsProducerInterceptor extends AbstractAutoLogCommonFilter { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/schedule/AutoLogScheduleInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor.schedule; 2 | 3 | import com.github.houbb.auto.log.core.support.interceptor.common.AbstractAutoLogCommonFilter; 4 | import com.github.houbb.auto.trace.constants.SpanTypeEnum; 5 | import com.github.houbb.auto.trace.constants.TraceTypeEnum; 6 | import com.github.houbb.auto.trace.interceptor.AbstractAutoTraceProxyInterceptor; 7 | import com.github.houbb.common.filter.annotation.FilterActive; 8 | import com.github.houbb.common.filter.api.Invoker; 9 | import com.github.houbb.common.proxy.core.core.impl.CommonProxyInvocation; 10 | import com.github.houbb.cross.thread.core.constant.CommonScheduleConst; 11 | 12 | /** 13 | * 任务调度的拦截器 14 | * 15 | * @since 0.11.0 16 | */ 17 | @FilterActive(group = CommonScheduleConst.COMMON_SCHEDULE_GROUP, 18 | order = CommonScheduleConst.COMMON_SCHEDULE_ORDER + 1) 19 | public class AutoLogScheduleInterceptor extends AbstractAutoLogCommonFilter { 20 | } 21 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/web/client/AutoLogHttpClientInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor.web.client; 2 | 3 | import com.github.houbb.auto.log.core.support.interceptor.common.AbstractAutoLogCommonFilter; 4 | import com.github.houbb.auto.trace.constants.AutoTraceConst; 5 | import com.github.houbb.common.filter.annotation.FilterActive; 6 | import com.github.houbb.http.client.core.constant.HttpClientGroupConst; 7 | 8 | /** 9 | * 客户端通用拦截器 10 | * @since 0.5.0 11 | */ 12 | @FilterActive(order = AutoTraceConst.ASPECT_ORDER + 1, 13 | group = HttpClientGroupConst.HTTP_CLIENT_GROUP) 14 | public class AutoLogHttpClientInterceptor extends AbstractAutoLogCommonFilter { 15 | } 16 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/web/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author d 3 | * @since 1.0.0 4 | */ 5 | package com.github.houbb.auto.log.core.support.interceptor.web; 6 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/interceptor/web/server/AutoLogHttpServerServletFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.interceptor.web.server; 2 | 3 | import com.github.houbb.auto.trace.interceptor.web.AbstractHttpServerInterceptor; 4 | import com.github.houbb.auto.trace.model.Span; 5 | 6 | import javax.servlet.*; 7 | import java.io.IOException; 8 | 9 | /** 10 | * 基于 servlet filter 的实现 11 | * @since 0.1.0 12 | */ 13 | public class AutoLogHttpServerServletFilter implements Filter { 14 | 15 | @Override 16 | public void init(FilterConfig filterConfig) throws ServletException { 17 | 18 | } 19 | 20 | @Override 21 | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { 22 | try { 23 | // 继续处理请求 24 | filterChain.doFilter(servletRequest, servletResponse); 25 | } finally { 26 | //TODO... 27 | } 28 | } 29 | 30 | @Override 31 | public void destroy() { 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/package-info.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support; -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/proxy/AutoLogProxy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019. houbinbin Inc. 3 | * async All rights reserved. 4 | */ 5 | 6 | package com.github.houbb.auto.log.core.support.proxy; 7 | 8 | import com.github.houbb.auto.log.core.support.proxy.cglib.CglibProxy; 9 | import com.github.houbb.auto.log.core.support.proxy.dynamic.DynamicProxy; 10 | import com.github.houbb.auto.log.core.support.proxy.none.NoneProxy; 11 | import com.github.houbb.heaven.util.lang.ObjectUtil; 12 | 13 | import java.lang.reflect.Proxy; 14 | 15 | /** 16 | *

代理信息

17 | * 18 | *
 Created: 2019/3/8 10:38 AM  
19 | *
 Project: async  
20 | * 21 | * @author houbinbin 22 | * @since 0.0.6 23 | */ 24 | public final class AutoLogProxy { 25 | 26 | private AutoLogProxy(){} 27 | 28 | /** 29 | * 获取对象代理 30 | * @param 泛型 31 | * @param object 对象代理 32 | * @return 代理信息 33 | * @since 0.0.6 34 | */ 35 | @SuppressWarnings("all") 36 | public static T getProxy(final T object) { 37 | if(ObjectUtil.isNull(object)) { 38 | return (T) new NoneProxy(object).proxy(); 39 | } 40 | 41 | final Class clazz = object.getClass(); 42 | 43 | // 如果targetClass本身是个接口或者targetClass是JDK Proxy生成的,则使用JDK动态代理。 44 | // 参考 spring 的 AOP 判断 45 | if (clazz.isInterface() || Proxy.isProxyClass(clazz)) { 46 | return (T) new DynamicProxy(object).proxy(); 47 | } 48 | 49 | return (T) new CglibProxy(object).proxy(); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/proxy/IAutoLogProxy.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.proxy; 2 | 3 | /** 4 | * 代理接口 5 | * @author binbin.hou 6 | * @since 0.0.6 7 | */ 8 | public interface IAutoLogProxy { 9 | 10 | /** 11 | * 获取代理实现 12 | * @return 代理 13 | * @since 0.0.6 14 | */ 15 | Object proxy(); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/proxy/cglib/CglibProxy.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.proxy.cglib; 2 | 3 | import com.github.houbb.auto.log.annotation.AutoLog; 4 | import com.github.houbb.auto.log.core.bs.AutoLogBs; 5 | import com.github.houbb.auto.log.core.core.impl.SimpleAutoLogContext; 6 | import com.github.houbb.auto.log.core.support.proxy.IAutoLogProxy; 7 | import net.sf.cglib.proxy.Enhancer; 8 | import net.sf.cglib.proxy.MethodInterceptor; 9 | import net.sf.cglib.proxy.MethodProxy; 10 | 11 | import java.lang.reflect.Method; 12 | 13 | /** 14 | * CGLIB 代理类 15 | * @author binbin.hou 16 | * date 2019/3/7 17 | * @since 0.0.2 18 | */ 19 | public class CglibProxy implements MethodInterceptor, IAutoLogProxy { 20 | 21 | /** 22 | * 被代理的对象 23 | */ 24 | private final Object target; 25 | 26 | public CglibProxy(Object target) { 27 | this.target = target; 28 | } 29 | 30 | @Override 31 | public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable { 32 | SimpleAutoLogContext context = SimpleAutoLogContext.newInstance(); 33 | context.method(method) 34 | .params(objects) 35 | .autoLog(method.getAnnotation(AutoLog.class)); 36 | context.target(target); 37 | 38 | return AutoLogBs.newInstance().context(context).execute(); 39 | } 40 | 41 | @Override 42 | public Object proxy() { 43 | Enhancer enhancer = new Enhancer(); 44 | //目标对象类 45 | enhancer.setSuperclass(target.getClass()); 46 | enhancer.setCallback(this); 47 | //通过字节码技术创建目标对象类的子类实例作为代理 48 | return enhancer.create(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/proxy/dynamic/DynamicProxy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019. houbinbin Inc. 3 | * async All rights reserved. 4 | */ 5 | 6 | package com.github.houbb.auto.log.core.support.proxy.dynamic; 7 | 8 | import com.github.houbb.auto.log.core.bs.AutoLogBs; 9 | import com.github.houbb.auto.log.core.core.impl.SimpleAutoLogContext; 10 | import com.github.houbb.auto.log.core.support.proxy.IAutoLogProxy; 11 | 12 | import java.lang.reflect.InvocationHandler; 13 | import java.lang.reflect.Method; 14 | import java.lang.reflect.Proxy; 15 | import java.util.concurrent.CompletionService; 16 | 17 | /** 18 | *

动态代理

19 | *

20 | * 1. 对于 executor 的抽象,使用 {@link CompletionService} 21 | * 2. 确保唯一初始化 executor,在任务执行的最后关闭 executor。 22 | * 3. 异步执行结果的获取,异常信息的获取。 23 | *

 Created: 2019/3/5 10:23 PM  
24 | *
 Project: async  
25 | * 26 | * @author houbinbin 27 | * @since 0.0.1 28 | */ 29 | public class DynamicProxy implements InvocationHandler, IAutoLogProxy { 30 | 31 | /** 32 | * 被代理的对象 33 | */ 34 | private final Object target; 35 | 36 | public DynamicProxy(Object target) { 37 | this.target = target; 38 | } 39 | 40 | /** 41 | * 这种方式虽然实现了异步执行,但是存在一个缺陷: 42 | * 强制用户返回值为 Future 的子类。 43 | *

44 | * 如何实现不影响原来的值,要怎么实现呢? 45 | * 46 | * @param proxy 原始对象 47 | * @param method 方法 48 | * @param args 入参 49 | * @return 结果 50 | * @throws Throwable 异常 51 | */ 52 | @Override 53 | @SuppressWarnings("all") 54 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 55 | SimpleAutoLogContext context = SimpleAutoLogContext.newInstance(); 56 | context.method(method) 57 | .params(args) 58 | ; 59 | 60 | context.target(target); 61 | return AutoLogBs.newInstance().context(context).execute(); 62 | } 63 | 64 | @Override 65 | public Object proxy() { 66 | // 我们要代理哪个真实对象,就将该对象传进去,最后是通过该真实对象来调用其方法的 67 | InvocationHandler handler = new DynamicProxy(target); 68 | 69 | return Proxy.newProxyInstance(handler.getClass().getClassLoader(), 70 | target.getClass().getInterfaces(), handler); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/proxy/dynamic/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019. houbinbin Inc. 3 | * async All rights reserved. 4 | */ 5 | 6 | /** 7 | *

动态代理

8 | * 9 | *
 Created: 2019-03-05 22:23  
10 | *
 Project: async  
11 | * 12 | * @author houbinbin 13 | */ 14 | package com.github.houbb.auto.log.core.support.proxy.dynamic; -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/proxy/none/NoneProxy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019. houbinbin Inc. 3 | * async All rights reserved. 4 | */ 5 | 6 | package com.github.houbb.auto.log.core.support.proxy.none; 7 | 8 | import com.github.houbb.auto.log.core.support.proxy.IAutoLogProxy; 9 | 10 | import java.lang.reflect.InvocationHandler; 11 | import java.lang.reflect.Method; 12 | 13 | /** 14 | *

没有代理

15 | * 16 | *
 Created: 2019/3/5 10:23 PM  
17 | *
 Project: async  
18 | * 19 | * @author houbinbin 20 | * @since 0.0.1 21 | */ 22 | public class NoneProxy implements InvocationHandler, IAutoLogProxy { 23 | 24 | /** 25 | * 代理对象 26 | */ 27 | private final Object target; 28 | 29 | public NoneProxy(Object target) { 30 | this.target = target; 31 | } 32 | 33 | @Override 34 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 35 | return method.invoke(proxy, args); 36 | } 37 | 38 | /** 39 | * 返回原始对象,没有代理 40 | * @return 原始对象 41 | */ 42 | @Override 43 | public Object proxy() { 44 | return this.target; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/proxy/package-info.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.proxy; -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/sample/AutoLogSampleConditionAdaptive.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.sample; 2 | 3 | import com.github.houbb.auto.log.api.IAutoLogContext; 4 | import com.github.houbb.auto.log.api.IAutoLogSampleCondition; 5 | 6 | import java.util.concurrent.ThreadLocalRandom; 7 | import java.util.concurrent.atomic.AtomicInteger; 8 | 9 | /** 10 | * 自适应采样 11 | * 12 | * 1. 初始化采样率为 100%,全部采样 13 | * 14 | * 2. QPS 如果越来越高,那么采样率应该越来越低。这样避免 cpu 等资源的损耗。最低为 1% 15 | * 如果 QPS 越来越低,采样率应该越来越高。增加样本,最高为 100% 16 | * 17 | * 3. QPS 如何计算问题 18 | * 19 | * 直接设置大小为 100 的队列,每一次在里面放入时间戳。 20 | * 当大小等于 100 的时候,计算首尾的时间差,currentQps = 100 / (endTime - startTime) * 1000 21 | * 22 | * 触发 rate 重新计算。 23 | * 24 | * 3.1 rate 计算逻辑 25 | * 26 | * 这里我们存储一下 preRate = 100, preQPS = ? 27 | * 28 | * newRate = (preQps / currentQps) * rate 29 | * 30 | * 范围限制: 31 | * newRate = Math.min(100, newRate); 32 | * newRate = Math.max(1, newRate); 33 | * 34 | * 3.2 时间队列的清空 35 | * 36 | * 更新完 rate 之后,对应的队列可以清空? 37 | * 38 | * 如果额外使用一个 count,好像也可以。 39 | * 可以调整为 atomicLong 的计算器,和 preTime。 40 | * 41 | * @author d 42 | * @since 0.5.0 43 | */ 44 | public class AutoLogSampleConditionAdaptive implements IAutoLogSampleCondition { 45 | 46 | private static final AutoLogSampleConditionAdaptive INSTANCE = new AutoLogSampleConditionAdaptive(); 47 | 48 | /** 49 | * 单例的方式获取实例 50 | * @return 结果 51 | */ 52 | public static AutoLogSampleConditionAdaptive getInstance() { 53 | return INSTANCE; 54 | } 55 | 56 | /** 57 | * 次数大小限制,即接收到多少次请求更新一次 adaptive 计算 58 | * 59 | * TODO: 这个如何可以让用户可以自定义呢?后续考虑配置从默认的配置文件中读取。 60 | */ 61 | private static final int COUNT_LIMIT = 1000; 62 | 63 | /** 64 | * 自适应比率,初始化为 100.全部采集 65 | */ 66 | private volatile int adaptiveRate = 100; 67 | 68 | /** 69 | * 上一次的 QPS 70 | * 71 | * TODO: 这个如何可以让用户可以自定义呢?后续考虑配置从默认的配置文件中读取。 72 | */ 73 | private volatile double preQps = 100.0; 74 | 75 | /** 76 | * 上一次的时间 77 | */ 78 | private volatile long preTime; 79 | 80 | /** 81 | * 总数,请求计数器 82 | */ 83 | private final AtomicInteger counter; 84 | 85 | public AutoLogSampleConditionAdaptive() { 86 | preTime = System.currentTimeMillis(); 87 | counter = new AtomicInteger(0); 88 | } 89 | 90 | @Override 91 | public boolean sampleCondition(IAutoLogContext context) { 92 | int count = counter.incrementAndGet(); 93 | 94 | // 触发一次重新计算 95 | if(count >= COUNT_LIMIT) { 96 | updateAdaptiveRate(); 97 | } 98 | 99 | // 直接计算是否满足 100 | return InnerRandomUtil.randomRateCondition(adaptiveRate); 101 | } 102 | 103 | /** 104 | * 更新自适应的概率 105 | * 106 | * 100 计算一次,其实还好。实际应该可以适当调大这个阈值,本身不会经常变化的东西。 107 | */ 108 | private synchronized void updateAdaptiveRate() { 109 | //消耗的毫秒数 110 | long costTimeMs = System.currentTimeMillis() - preTime; 111 | //qps 的计算,时间差是毫秒。所以次数需要乘以 1000 112 | double currentQps = COUNT_LIMIT*1000.0 / costTimeMs; 113 | // preRate * preQps = currentRate * currentQps; 保障采样均衡,服务器压力均衡 114 | // currentRate = (preRate * preQps) / currentQps; 115 | // 更新比率 116 | int newRate = 100; 117 | if(currentQps > 0) { 118 | newRate = (int) ((adaptiveRate * preQps) / currentQps); 119 | newRate = Math.min(100, newRate); 120 | newRate = Math.max(1, newRate); 121 | } 122 | 123 | // 更新 rate 124 | adaptiveRate = newRate; 125 | // 更新 QPS 126 | preQps = currentQps; 127 | // 更新上一次的时间内戳 128 | preTime = System.currentTimeMillis(); 129 | // 归零 130 | counter.set(0); 131 | } 132 | 133 | 134 | } 135 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/sample/AutoLogSampleConditionAdaptiveSchedule.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.sample; 2 | 3 | import com.github.houbb.auto.log.api.IAutoLogContext; 4 | import com.github.houbb.auto.log.api.IAutoLogSampleCondition; 5 | 6 | import java.util.concurrent.Executors; 7 | import java.util.concurrent.ScheduledExecutorService; 8 | import java.util.concurrent.TimeUnit; 9 | import java.util.concurrent.atomic.AtomicInteger; 10 | import java.util.concurrent.atomic.AtomicLong; 11 | 12 | /** 13 | * 自适应采样-时间窗口 14 | * 15 | * 1. 初始化采样率为 100%,全部采样 16 | * 17 | * 2. QPS 如果越来越高,那么采样率应该越来越低。这样避免 cpu 等资源的损耗。最低为 1% 18 | * 如果 QPS 越来越低,采样率应该越来越高。增加样本,最高为 100% 19 | * 20 | * 3. QPS 如何计算问题 21 | * 22 | * 直接设置大小为 100 的队列,每一次在里面放入时间戳。 23 | * 当大小等于 100 的时候,计算首尾的时间差,currentQps = 100 / (endTime - startTime) * 1000 24 | * 25 | * 触发 rate 重新计算。 26 | * 27 | * 3.1 rate 计算逻辑 28 | * 29 | * 这里我们存储一下 preRate = 100, preQPS = ? 30 | * 31 | * newRate = (preQps / currentQps) * rate 32 | * 33 | * 范围限制: 34 | * newRate = Math.min(100, newRate); 35 | * newRate = Math.max(1, newRate); 36 | * 37 | * 3.2 时间队列的清空 38 | * 39 | * 更新完 rate 之后,对应的队列可以清空? 40 | * 41 | * 如果额外使用一个 count,好像也可以。 42 | * 可以调整为 atomicLong 的计算器,和 preTime。 43 | * 44 | * @author d 45 | * @since 0.5.0 46 | */ 47 | public class AutoLogSampleConditionAdaptiveSchedule implements IAutoLogSampleCondition { 48 | 49 | private static final AutoLogSampleConditionAdaptiveSchedule INSTANCE = new AutoLogSampleConditionAdaptiveSchedule(); 50 | 51 | /** 52 | * 单例的方式获取实例 53 | * @return 结果 54 | */ 55 | public static AutoLogSampleConditionAdaptiveSchedule getInstance() { 56 | return INSTANCE; 57 | } 58 | 59 | private static final ScheduledExecutorService EXECUTOR_SERVICE = Executors.newSingleThreadScheduledExecutor(); 60 | 61 | /** 62 | * 时间分钟间隔 63 | */ 64 | private static final int TIME_INTERVAL_MINUTES = 5; 65 | 66 | /** 67 | * 自适应比率,初始化为 100.全部采集 68 | */ 69 | private volatile int adaptiveRate = 100; 70 | 71 | /** 72 | * 上一次的总数 73 | * 74 | * TODO: 这个如何可以让用户可以自定义呢?后续考虑配置从默认的配置文件中读取。 75 | */ 76 | private volatile long preCount; 77 | 78 | /** 79 | * 总数,请求计数器 80 | */ 81 | private final AtomicLong counter; 82 | 83 | public AutoLogSampleConditionAdaptiveSchedule() { 84 | counter = new AtomicLong(0); 85 | preCount = TIME_INTERVAL_MINUTES * 60 * 100; 86 | 87 | //1. 1min 后开始执行 88 | //2. 中间默认 5 分钟更新一次 89 | EXECUTOR_SERVICE.scheduleAtFixedRate(new Runnable() { 90 | @Override 91 | public void run() { 92 | updateAdaptiveRate(); 93 | } 94 | }, 60, TIME_INTERVAL_MINUTES * 60, TimeUnit.SECONDS); 95 | } 96 | 97 | @Override 98 | public boolean sampleCondition(IAutoLogContext context) { 99 | counter.incrementAndGet(); 100 | 101 | // 直接计算是否满足 102 | return InnerRandomUtil.randomRateCondition(adaptiveRate); 103 | } 104 | 105 | /** 106 | * 更新自适应的概率 107 | * 108 | * QPS = count / time_interval 109 | * 110 | * 其中时间维度是固定的,所以可以不用考虑时间。 111 | */ 112 | private synchronized void updateAdaptiveRate() { 113 | // preRate * preCount = currentRate * currentCount; 保障采样均衡,服务器压力均衡 114 | // currentRate = (preRate * preCount) / currentCount; 115 | // 更新比率 116 | long currentCount = counter.get(); 117 | int newRate = 100; 118 | if(currentCount != 0) { 119 | newRate = (int) ((adaptiveRate * preCount) / currentCount); 120 | newRate = Math.min(100, newRate); 121 | newRate = Math.max(1, newRate); 122 | } 123 | 124 | // 更新自适应频率 125 | adaptiveRate = newRate; 126 | 127 | // 更新 QPS 128 | preCount = currentCount; 129 | // 归零 130 | counter.set(0); 131 | } 132 | 133 | 134 | } 135 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/sample/AutoLogSampleConditionRate.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.sample; 2 | 3 | import com.github.houbb.auto.log.api.IAutoLogContext; 4 | import com.github.houbb.auto.log.api.IAutoLogSampleCondition; 5 | 6 | import java.util.concurrent.ThreadLocalRandom; 7 | 8 | /** 9 | * 概率采样 10 | * 11 | * @author d 12 | * @since 0.5.0 13 | */ 14 | public class AutoLogSampleConditionRate implements IAutoLogSampleCondition { 15 | 16 | /** 17 | * 比率 18 | */ 19 | private final int rate; 20 | 21 | public AutoLogSampleConditionRate(int rate) { 22 | this.rate = rate; 23 | } 24 | 25 | public AutoLogSampleConditionRate() { 26 | this(100); 27 | } 28 | 29 | @Override 30 | public boolean sampleCondition(IAutoLogContext context) { 31 | return InnerRandomUtil.randomRateCondition(rate); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/sample/AutoLogSampleConditions.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.sample; 2 | 3 | import com.github.houbb.auto.log.api.IAutoLogSampleCondition; 4 | 5 | /** 6 | * @author d 7 | * @since 0.5.0 8 | */ 9 | public class AutoLogSampleConditions { 10 | 11 | /** 12 | * 概率 13 | * @param rate 概率 14 | * @return 结果 15 | * @since 0.5.0 16 | */ 17 | public static IAutoLogSampleCondition rate(final int rate) { 18 | return new AutoLogSampleConditionRate(rate); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /auto-log-core/src/main/java/com/github/houbb/auto/log/core/support/sample/InnerRandomUtil.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.support.sample; 2 | 3 | import java.util.concurrent.ThreadLocalRandom; 4 | 5 | /** 6 | * @author d 7 | * @since 0.6.0 8 | */ 9 | public class InnerRandomUtil { 10 | 11 | /** 12 | * 1. 计算一个 1-100 的随机数 randomVal 13 | * 2. targetRatePercent 值越大,则返回 true 的概率越高 14 | * @param targetRatePercent 目标百分比 15 | * @return 结果 16 | */ 17 | public static boolean randomRateCondition(int targetRatePercent) { 18 | if(targetRatePercent <= 0) { 19 | return false; 20 | } 21 | if(targetRatePercent >= 100) { 22 | return true; 23 | } 24 | 25 | // 随机 26 | ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current(); 27 | int value = threadLocalRandom.nextInt(1, 100); 28 | 29 | // 随机概率 30 | return targetRatePercent >= value; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /auto-log-core/src/main/resources/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter: -------------------------------------------------------------------------------- 1 | autoLogDubboConsumerFilter=com.github.houbb.auto.log.core.support.interceptor.dubbo.AutoLogDubboConsumerFilter 2 | autoLogDubboProviderFilter=com.github.houbb.auto.log.core.support.interceptor.dubbo.AutoLogDubboProviderFilter 3 | -------------------------------------------------------------------------------- /auto-log-core/src/main/resources/META-INF/services/com.github.houbb.common.filter.api.CommonFilter: -------------------------------------------------------------------------------- 1 | com.github.houbb.auto.log.core.support.interceptor.cache.AutoLogCacheInterceptor 2 | com.github.houbb.auto.log.core.support.interceptor.chain.AutoLogCommonFilter 3 | com.github.houbb.auto.log.core.support.interceptor.jms.AutoLogJmsProducerInterceptor 4 | com.github.houbb.auto.log.core.support.interceptor.jms.AutoLogJmsConsumerInterceptor 5 | com.github.houbb.auto.log.core.support.interceptor.schedule.AutoLogScheduleInterceptor 6 | com.github.houbb.auto.log.core.support.interceptor.web.client.AutoLogHttpClientInterceptor 7 | -------------------------------------------------------------------------------- /auto-log-spring/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | auto-log 7 | com.github.houbb 8 | 0.12.0 9 | 10 | 4.0.0 11 | 12 | auto-log-spring 13 | 14 | 15 | 16 | 17 | com.github.houbb 18 | auto-log-annotation 19 | 20 | 21 | com.github.houbb 22 | auto-log-core 23 | 24 | 25 | com.github.houbb 26 | auto-trace-spring 27 | 28 | 29 | 30 | 31 | com.github.houbb 32 | aop-spring 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /auto-log-spring/src/main/java/com/github/houbb/auto/log/spring/annotation/EnableAutoLog.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.spring.annotation; 2 | 3 | import com.github.houbb.auto.log.spring.config.AutoLogAopConfig; 4 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 5 | import org.springframework.context.annotation.Import; 6 | 7 | import java.lang.annotation.*; 8 | 9 | /** 10 | * 启用自动日志注解 11 | * @author binbin.hou 12 | * @since 0.0.3 13 | */ 14 | @Target(ElementType.TYPE) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Documented 17 | @Import(AutoLogAopConfig.class) 18 | @EnableAspectJAutoProxy 19 | public @interface EnableAutoLog { 20 | } 21 | -------------------------------------------------------------------------------- /auto-log-spring/src/main/java/com/github/houbb/auto/log/spring/aop/AutoLogAdvice.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.spring.aop; 2 | 3 | import com.github.houbb.auto.log.annotation.AutoLog; 4 | import com.github.houbb.auto.log.core.bs.AutoLogBs; 5 | import com.github.houbb.auto.log.spring.config.DefaultAutoLogGlobalConfig; 6 | import org.aopalliance.intercept.MethodInterceptor; 7 | import org.aopalliance.intercept.MethodInvocation; 8 | import org.springframework.core.annotation.AnnotationUtils; 9 | 10 | import java.lang.reflect.Method; 11 | 12 | /** 13 | * 切面拦截器 14 | * 15 | * @author binbin.hou 16 | * @since 0.3.0 17 | */ 18 | public class AutoLogAdvice implements MethodInterceptor { 19 | 20 | private AutoLog getAutoLogAnnotation(final MethodInvocation methodInvocation) { 21 | //1. 方法级别 22 | Method method = methodInvocation.getMethod(); 23 | AutoLog autoLog = AnnotationUtils.getAnnotation(method, AutoLog.class); 24 | if (autoLog != null) { 25 | return autoLog; 26 | } 27 | 28 | //2. 类级别 29 | final Class targetClass = methodInvocation.getThis().getClass(); 30 | autoLog = targetClass.getAnnotation(AutoLog.class); 31 | if (autoLog != null) { 32 | return autoLog; 33 | } 34 | 35 | //3. 默认的注解信息 36 | return DefaultAutoLogGlobalConfig.class.getAnnotation(AutoLog.class); 37 | } 38 | 39 | @Override 40 | public Object invoke(MethodInvocation methodInvocation) throws Throwable { 41 | AutoLog autoLog = getAutoLogAnnotation(methodInvocation); 42 | 43 | // 如果存在,则执行切面的逻辑 44 | AutoLogAdviceContext logContext = AutoLogAdviceContext.newInstance(); 45 | logContext.methodInvocation(methodInvocation) 46 | .method(methodInvocation.getMethod()) 47 | .autoLog(autoLog) 48 | .params(methodInvocation.getArguments()) 49 | ; 50 | 51 | return AutoLogBs.newInstance() 52 | .context(logContext) 53 | .execute(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /auto-log-spring/src/main/java/com/github/houbb/auto/log/spring/aop/AutoLogAdviceContext.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.spring.aop; 2 | 3 | import com.github.houbb.auto.log.core.core.impl.AbstractAutoLogContext; 4 | import org.aopalliance.intercept.MethodInvocation; 5 | 6 | /** 7 | * 切面拦截器 8 | * 9 | * @author binbin.hou 10 | * @since 0.3.0 11 | */ 12 | public class AutoLogAdviceContext extends AbstractAutoLogContext { 13 | 14 | public static AutoLogAdviceContext newInstance() { 15 | return new AutoLogAdviceContext(); 16 | } 17 | 18 | private MethodInvocation methodInvocation; 19 | 20 | public MethodInvocation methodInvocation() { 21 | return methodInvocation; 22 | } 23 | 24 | public AutoLogAdviceContext methodInvocation(MethodInvocation methodInvocation) { 25 | this.methodInvocation = methodInvocation; 26 | return this; 27 | } 28 | 29 | @Override 30 | public Object process() throws Throwable { 31 | return methodInvocation.proceed(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /auto-log-spring/src/main/java/com/github/houbb/auto/log/spring/aop/AutoLogAop.java: -------------------------------------------------------------------------------- 1 | //package com.github.houbb.auto.log.spring.aop; 2 | // 3 | //import com.github.houbb.aop.spring.util.SpringAopUtil; 4 | //import com.github.houbb.auto.log.annotation.AutoLog; 5 | //import com.github.houbb.auto.log.core.bs.AutoLogBs; 6 | //import com.github.houbb.auto.log.spring.context.SpringAopAutoLogContext; 7 | //import org.aspectj.lang.ProceedingJoinPoint; 8 | //import org.aspectj.lang.annotation.Around; 9 | //import org.aspectj.lang.annotation.Pointcut; 10 | //import org.springframework.core.annotation.AnnotationUtils; 11 | // 12 | //import java.lang.reflect.Method; 13 | // 14 | ///** 15 | // * 这是一种写法 16 | // * 自动日志输出 aop 17 | // * @author binbin.hou 18 | // * @since 0.0.3 19 | // */ 20 | ////@Aspect 21 | ////@Component 22 | ////@EnableAspectJAutoProxy 23 | //@Deprecated 24 | //public class AutoLogAop { 25 | // 26 | // /** 27 | // * 28 | // * 切面方法: 29 | // * 30 | // * (1)扫描所有的共有方法 31 | // *
 32 | //     *     execution(public * *(..))
 33 | //     * 
34 | // * 35 | // * 问题:切面太大,废弃。 36 | // * 使用扫描注解的方式替代。 37 | // * 38 | // * (2)扫描指定注解的方式 39 | // * 40 | // * 其实可以在 aop 中直接获取到注解信息,暂时先不调整。 41 | // * 暂时先不添加 public 的限定 42 | // * 43 | // * (3)直接改成注解的优缺点: 44 | // * 优点:减少了 aop 的切面访问 45 | // * 缺点:弱化了注解的特性,本来是只要是 {@link com.github.houbb.auto.log.annotation.AutoLog} 指定的注解即可, 46 | // * 47 | // * 不过考虑到使用者的熟练度,如果用户知道了自定义注解,自定义 aop 应该也不是问题。 48 | // * 49 | // * // 匹配任意public方法 50 | // * execution(public * *(..)) 51 | // * // 匹配任意以set开头的方法 52 | // * execution(* set*(..)) 53 | // * // 匹配AccountService接口中定义的任意方法 54 | // * execution(* com.xyz.service.AccountService.*(..)) 55 | // * // 匹配service包定义的任意方法 56 | // * execution(* com.xyz.service.*.*(..)) 57 | // * // 匹配service或其子包中定义的任意方法 58 | // * execution(* com.xyz.service..*.*(..)) 59 | // * 60 | // */ 61 | // @Pointcut("@within(com.github.houbb.auto.log.annotation.AutoLog)" + 62 | // "|| @annotation(com.github.houbb.auto.log.annotation.AutoLog)") 63 | // public void autoLogPointcut() { 64 | // } 65 | // 66 | // /** 67 | // * 执行核心方法 68 | // * 69 | // * 相当于 MethodInterceptor 70 | // * 71 | // * @param point 切点 72 | // * @return 结果 73 | // * @throws Throwable 异常信息 74 | // * @since 0.0.3 75 | // */ 76 | // @Around("autoLogPointcut()") 77 | // public Object around(ProceedingJoinPoint point) throws Throwable { 78 | // Method method = SpringAopUtil.getCurrentMethod(point); 79 | // AutoLog autoLog = AnnotationUtils.getAnnotation(method, AutoLog.class); 80 | // 81 | // //获取当前类注解信息 82 | // if(autoLog == null) { 83 | // autoLog = SpringAopUtil.getClassAnnotation(point, AutoLog.class); 84 | // } 85 | // 86 | // // 如果不存在 87 | // if(autoLog == null) { 88 | // return point.proceed(); 89 | // } 90 | // // 如果存在,则执行切面的逻辑 91 | // SpringAopAutoLogContext logContext = SpringAopAutoLogContext.newInstance(); 92 | // logContext.method(method) 93 | // .autoLog(autoLog) 94 | // .params(point.getArgs()); 95 | // logContext.point(point); 96 | // return AutoLogBs.newInstance() 97 | // .context(logContext) 98 | // .execute(); 99 | // } 100 | // 101 | //} 102 | -------------------------------------------------------------------------------- /auto-log-spring/src/main/java/com/github/houbb/auto/log/spring/aop/AutoLogDynamicPointcut.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.spring.aop; 2 | 3 | import org.aspectj.lang.annotation.Aspect; 4 | import org.springframework.aop.aspectj.AspectJExpressionPointcutAdvisor; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 9 | import org.springframework.stereotype.Component; 10 | 11 | /** 12 | * 动态配置的切面 13 | * 自动日志输出 aop 14 | * @author binbin.hou 15 | * @since 0.3.0 16 | */ 17 | @Configuration 18 | @Aspect 19 | //@EnableAspectJAutoProxy 20 | public class AutoLogDynamicPointcut { 21 | 22 | /** 23 | * 切面设置,直接和 spring 的配置对应 ${},可以从 properties 或者配置中心读取。更加灵活 24 | */ 25 | @Value("${auto.log.pointcut:@within(com.github.houbb.auto.log.annotation.AutoLog)||@annotation(com.github.houbb.auto.log.annotation.AutoLog)}") 26 | private String pointcut; 27 | 28 | @Bean("autoLogPointcutAdvisor") 29 | public AspectJExpressionPointcutAdvisor autoLogPointcutAdvisor() { 30 | AspectJExpressionPointcutAdvisor advisor = new AspectJExpressionPointcutAdvisor(); 31 | advisor.setExpression(pointcut); 32 | advisor.setAdvice(new AutoLogAdvice()); 33 | return advisor; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /auto-log-spring/src/main/java/com/github/houbb/auto/log/spring/config/AutoLogAopConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.spring.config; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | /** 7 | * 自动日志 aop 配置 8 | * 9 | * https://blog.csdn.net/u013905744/article/details/91364736 10 | * @author binbin.hou 11 | * @since 0.0.3 12 | */ 13 | @Configuration 14 | @ComponentScan(basePackages = "com.github.houbb.auto.log.spring") 15 | public class AutoLogAopConfig { 16 | } 17 | -------------------------------------------------------------------------------- /auto-log-spring/src/main/java/com/github/houbb/auto/log/spring/config/DefaultAutoLogGlobalConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.spring.config; 2 | 3 | import com.github.houbb.auto.log.annotation.AutoLog; 4 | import org.springframework.context.annotation.ComponentScan; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * 默认全局配置 9 | * 10 | * @author binbin.hou 11 | * @since 0.0.3 12 | */ 13 | @AutoLog 14 | public class DefaultAutoLogGlobalConfig { 15 | } 16 | -------------------------------------------------------------------------------- /auto-log-spring/src/main/java/com/github/houbb/auto/log/spring/context/SpringAopAutoLogContext.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.spring.context; 2 | 3 | import com.github.houbb.auto.log.core.core.impl.AbstractAutoLogContext; 4 | import org.aspectj.lang.ProceedingJoinPoint; 5 | 6 | /** 7 | * @author binbin.hou 8 | * @since 0.0.7 9 | */ 10 | public class SpringAopAutoLogContext extends AbstractAutoLogContext { 11 | 12 | /** 13 | * 切面信息 14 | * @since 0.0.7 15 | */ 16 | private ProceedingJoinPoint point; 17 | 18 | /** 19 | * 新建对象实例 20 | * @return 实例 21 | * @since 0.0.7 22 | */ 23 | public static SpringAopAutoLogContext newInstance() { 24 | return new SpringAopAutoLogContext(); 25 | } 26 | 27 | public SpringAopAutoLogContext point(ProceedingJoinPoint point) { 28 | this.point = point; 29 | return this; 30 | } 31 | 32 | @Override 33 | public Object process() throws Throwable { 34 | return point.proceed(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /auto-log-spring/src/main/java/com/github/houbb/auto/log/spring/package-info.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.spring; -------------------------------------------------------------------------------- /auto-log-springboot-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | auto-log 7 | com.github.houbb 8 | 0.12.0 9 | 10 | 4.0.0 11 | 12 | auto-log-springboot-starter 13 | 14 | 15 | 16 | com.github.houbb 17 | auto-log-spring 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter 23 | 24 | 25 | -------------------------------------------------------------------------------- /auto-log-springboot-starter/src/main/java/com/github/houbb/auto/log/springboot/starter/config/AutoLogAutoConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.springboot.starter.config; 2 | 3 | import com.github.houbb.auto.log.spring.annotation.EnableAutoLog; 4 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * 防止重复提交自动配置 9 | * @author binbin.hou 10 | * @since 0.0.3 11 | */ 12 | @Configuration 13 | @ConditionalOnClass(EnableAutoLog.class) 14 | @EnableAutoLog 15 | public class AutoLogAutoConfig { 16 | } 17 | -------------------------------------------------------------------------------- /auto-log-springboot-starter/src/main/java/com/github/houbb/auto/log/springboot/starter/package-info.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.springboot.starter; -------------------------------------------------------------------------------- /auto-log-springboot-starter/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.github.houbb.auto.log.springboot.starter.config.AutoLogAutoConfig -------------------------------------------------------------------------------- /auto-log-test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | auto-log 7 | com.github.houbb 8 | 0.12.0 9 | 10 | 4.0.0 11 | 12 | auto-log-test 13 | 14 | 15 | 16 | 17 | com.github.houbb 18 | auto-log-core 19 | 20 | 21 | com.github.houbb 22 | auto-log-spring 23 | 24 | 25 | com.github.houbb 26 | test-spring 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /auto-log-test/src/main/java/com/github/houbb/auto/log/test/config/SpringConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.test.config; 2 | 3 | 4 | import com.github.houbb.auto.log.spring.annotation.EnableAutoLog; 5 | import org.springframework.beans.factory.annotation.Configurable; 6 | import org.springframework.context.annotation.ComponentScan; 7 | 8 | /** 9 | * @author binbin.hou 10 | * @since 0.0.3 11 | */ 12 | @Configurable 13 | @ComponentScan(basePackages = "com.github.houbb.auto.log.test.service") 14 | @EnableAutoLog 15 | public class SpringConfig { 16 | } 17 | -------------------------------------------------------------------------------- /auto-log-test/src/main/java/com/github/houbb/auto/log/test/dynamic/SpringDynamicConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.test.dynamic; 2 | 3 | 4 | import com.github.houbb.auto.log.spring.annotation.EnableAutoLog; 5 | import org.springframework.beans.factory.annotation.Configurable; 6 | import org.springframework.context.annotation.ComponentScan; 7 | import org.springframework.context.annotation.PropertySource; 8 | 9 | /** 10 | * @author binbin.hou 11 | * @since 0.0.3 12 | */ 13 | @Configurable 14 | @ComponentScan(basePackages = "com.github.houbb.auto.log.test.dynamic.service") 15 | @EnableAutoLog 16 | @PropertySource("classpath:autoLogConfig.properties") 17 | public class SpringDynamicConfig { 18 | } 19 | -------------------------------------------------------------------------------- /auto-log-test/src/main/java/com/github/houbb/auto/log/test/dynamic/service/MyAddressService.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.test.dynamic.service; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public class MyAddressService { 7 | 8 | public String queryAddress(String id) { 9 | return "address-" + id; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /auto-log-test/src/main/java/com/github/houbb/auto/log/test/dynamic/service/MyUserService.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.test.dynamic.service; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public class MyUserService { 7 | 8 | public String queryUser(String id) { 9 | return "user-" + id; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /auto-log-test/src/main/java/com/github/houbb/auto/log/test/filter/MyParamFilter.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.test.filter; 2 | 3 | import com.github.houbb.auto.log.core.support.filter.param.AbstractParamFilter; 4 | 5 | /** 6 | * @author binbin.hou 7 | * @since 0.0.12 8 | */ 9 | public class MyParamFilter extends AbstractParamFilter { 10 | 11 | @Override 12 | protected Object[] doFilter(Object[] params) { 13 | Object[] newParams = new Object[1]; 14 | newParams[0] = "设置我我想要的值"; 15 | return newParams; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /auto-log-test/src/main/java/com/github/houbb/auto/log/test/interceptor/MyAutoLogInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.test.interceptor; 2 | 3 | import com.github.houbb.auto.log.core.constant.AutoLogAttachmentKeyConst; 4 | import com.github.houbb.common.filter.annotation.FilterActive; 5 | import com.github.houbb.common.filter.api.CommonFilter; 6 | import com.github.houbb.common.filter.api.Invocation; 7 | import com.github.houbb.common.filter.api.Invoker; 8 | import com.github.houbb.common.filter.api.Result; 9 | import com.github.houbb.common.filter.exception.CommonFilterException; 10 | 11 | /** 12 | * 自定义日志拦截器 13 | * @author binbin.hou 14 | * @since 0.0.12 15 | */ 16 | @FilterActive(order = 1) 17 | public class MyAutoLogInterceptor implements CommonFilter { 18 | 19 | @Override 20 | public Result invoke(Invoker invoker, Invocation invocation) throws CommonFilterException { 21 | final String tid = (String) invocation.getAttachment(AutoLogAttachmentKeyConst.AUTO_LOG_TRACE_ID); 22 | System.out.println("my test filter before " + tid); 23 | Result result = invoker.invoke(invocation); 24 | System.out.println("my test filter after " + tid); 25 | 26 | return result; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /auto-log-test/src/main/java/com/github/houbb/auto/log/test/package-info.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.test; -------------------------------------------------------------------------------- /auto-log-test/src/main/java/com/github/houbb/auto/log/test/service/DiscardService.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.test.service; 2 | 3 | import com.github.houbb.auto.log.annotation.AutoLog; 4 | import com.github.houbb.heaven.util.lang.CharUtil; 5 | import com.github.houbb.heaven.util.lang.StringUtil; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author d 11 | * @since 0.11.0 12 | */ 13 | public class DiscardService { 14 | 15 | @AutoLog 16 | public List queryByIds(List ids) { 17 | return ids; 18 | } 19 | 20 | @AutoLog 21 | public String getString(int len) { 22 | return CharUtil.repeat('*', len); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /auto-log-test/src/main/java/com/github/houbb/auto/log/test/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.test.service; 2 | 3 | /** 4 | * @author binbin.hou 5 | * @since 0.0.2 6 | */ 7 | public interface UserService { 8 | 9 | String query(final String id); 10 | 11 | String queryLog(final String id); 12 | 13 | /** 14 | * 慢日志 15 | * @param id 标识 16 | * @return 结果 17 | * @since 0.0.4 18 | */ 19 | String slowLog(final String id); 20 | 21 | /** 22 | * @since 0.0.8 23 | * @param id id 24 | * @return 结果 25 | */ 26 | String traceId(String id); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /auto-log-test/src/main/java/com/github/houbb/auto/log/test/service/annotation/AutoLogMethod.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/houbb/auto-log/f482b512aba2e020e5fabfd75a1d549bb6f968af/auto-log-test/src/main/java/com/github/houbb/auto/log/test/service/annotation/AutoLogMethod.java -------------------------------------------------------------------------------- /auto-log-test/src/main/java/com/github/houbb/auto/log/test/service/impl/ClassAnnotationService.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.test.service.impl; 2 | 3 | import com.github.houbb.auto.log.annotation.AutoLog; 4 | import org.springframework.stereotype.Service; 5 | 6 | /** 7 | * @author binbin.hou 8 | * @since 0.0.10 9 | */ 10 | @Service 11 | @AutoLog(costTime = true) 12 | public class ClassAnnotationService { 13 | 14 | public String enable() { 15 | return "enable"; 16 | } 17 | 18 | @AutoLog(enable = false) 19 | public String disable() { 20 | return "disable"; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /auto-log-test/src/main/java/com/github/houbb/auto/log/test/service/impl/DefineService.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.test.service.impl; 2 | 3 | import com.github.houbb.auto.log.annotation.AutoLog; 4 | import com.github.houbb.auto.log.test.filter.MyParamFilter; 5 | import com.github.houbb.auto.log.test.interceptor.MyAutoLogInterceptor; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * 自定义实现类 10 | * @author binbin.hou 11 | * @since 0.0.10 12 | */ 13 | @Service 14 | public class DefineService { 15 | 16 | /** 17 | * @return 结果 18 | * @since 0.0.10 19 | */ 20 | @AutoLog 21 | public String interceptor() { 22 | return "自定义策略"; 23 | } 24 | 25 | /** 26 | * @return 结果 27 | * @since 0.0.12 28 | */ 29 | @AutoLog 30 | public String paramFilter() { 31 | return "自定义入参过滤器"; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /auto-log-test/src/main/java/com/github/houbb/auto/log/test/service/impl/MenuServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.test.service.impl; 2 | 3 | import com.github.houbb.auto.log.annotation.AutoLog; 4 | import org.springframework.stereotype.Service; 5 | 6 | /** 7 | * @author binbin.hou 8 | * @since 0.0.2 9 | */ 10 | @Service 11 | public class MenuServiceImpl { 12 | 13 | @AutoLog 14 | public String query(final String id) { 15 | return "result-" + id; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /auto-log-test/src/main/java/com/github/houbb/auto/log/test/service/impl/MethodAtServiceImpl.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/houbb/auto-log/f482b512aba2e020e5fabfd75a1d549bb6f968af/auto-log-test/src/main/java/com/github/houbb/auto/log/test/service/impl/MethodAtServiceImpl.java -------------------------------------------------------------------------------- /auto-log-test/src/main/java/com/github/houbb/auto/log/test/service/impl/PrivateUserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.test.service.impl; 2 | 3 | import com.github.houbb.auto.log.annotation.AutoLog; 4 | import com.github.houbb.auto.log.test.service.UserService; 5 | import org.springframework.stereotype.Service; 6 | 7 | import java.util.concurrent.TimeUnit; 8 | 9 | /** 10 | * @author binbin.hou 11 | * @since 0.0.2 12 | */ 13 | @Service 14 | public class PrivateUserServiceImpl { 15 | 16 | @AutoLog(description = "私有查询日志") 17 | private String privateQueryLog() { 18 | return "private"; 19 | } 20 | 21 | @AutoLog(description = "public查询日志") 22 | public void callPrivate() { 23 | String result = privateQueryLog(); 24 | 25 | System.out.println("done"); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /auto-log-test/src/main/java/com/github/houbb/auto/log/test/service/impl/SampleRateServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.test.service.impl; 2 | 3 | import com.github.houbb.auto.log.annotation.AutoLog; 4 | import com.github.houbb.auto.log.core.support.sample.AutoLogSampleConditionRate; 5 | import org.springframework.stereotype.Service; 6 | 7 | /** 8 | * @author binbin.hou 9 | * @since 0.5.0 10 | */ 11 | @Service 12 | public class SampleRateServiceImpl { 13 | 14 | @AutoLog(sampleCondition = AutoLogSampleConditionRate.class, 15 | sampleRate = 30) 16 | public void sample30Test(int value) { 17 | System.out.println("i==" + value); 18 | } 19 | 20 | @AutoLog(sampleCondition = AutoLogSampleConditionRate.class, 21 | sampleRate = 50) 22 | public void sample50Test(int value) { 23 | System.out.println("i==" + value); 24 | } 25 | 26 | @AutoLog(sampleCondition = AutoLogSampleConditionRate.class, 27 | sampleRate = 0) 28 | public void sample0Test(int value) { 29 | System.out.println("i==" + value); 30 | } 31 | 32 | @AutoLog(sampleCondition = AutoLogSampleConditionRate.class, 33 | sampleRate = 100) 34 | public void sample100Test(int value) { 35 | System.out.println("i==" + value); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /auto-log-test/src/main/java/com/github/houbb/auto/log/test/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.test.service.impl; 2 | 3 | import com.github.houbb.auto.log.annotation.AutoLog; 4 | import com.github.houbb.auto.log.test.service.UserService; 5 | import org.springframework.stereotype.Service; 6 | 7 | import java.util.concurrent.TimeUnit; 8 | 9 | /** 10 | * @author binbin.hou 11 | * @since 0.0.2 12 | */ 13 | @Service 14 | //@AutoLog 15 | public class UserServiceImpl implements UserService { 16 | 17 | @Override 18 | public String query(final String id) { 19 | return "result-" + id; 20 | } 21 | 22 | @Override 23 | @AutoLog(description = "查询日志", enableTraceId = true) 24 | public String queryLog(String id) { 25 | return this.query(id); 26 | } 27 | 28 | @AutoLog(description = "私有查询日志") 29 | private String privateQueryLog(String id) { 30 | return this.query(id); 31 | } 32 | 33 | @Override 34 | @AutoLog(slowThresholdMills = 1000) 35 | public String slowLog(String id) { 36 | try { 37 | TimeUnit.SECONDS.sleep(2); 38 | return "slow-" + id; 39 | } catch (InterruptedException e) { 40 | throw new RuntimeException(e); 41 | } 42 | } 43 | 44 | @Override 45 | @AutoLog 46 | public String traceId(String id) { 47 | return id+"-1"; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /auto-log-test/src/main/resources/autoLogConfig.properties: -------------------------------------------------------------------------------- 1 | auto.log.pointcut=execution(* com.github.houbb.auto.log.test.dynamic.service.MyAddressService.*(..)) -------------------------------------------------------------------------------- /auto-log-test/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /auto-log-test/src/test/java/com/github/houbb/auto/log/core/bs/AutoLogBsRateTest.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.bs; 2 | 3 | import com.github.houbb.auto.log.core.support.proxy.AutoLogProxy; 4 | import com.github.houbb.auto.log.test.service.impl.*; 5 | import org.junit.Test; 6 | 7 | /** 8 | * @author binbin.hou 9 | * @since 0.5.0 10 | */ 11 | public class AutoLogBsRateTest { 12 | 13 | @Test 14 | public void rate30Test() { 15 | SampleRateServiceImpl userService = AutoLogProxy.getProxy(new SampleRateServiceImpl()); 16 | for(int i = 0; i < 10; i++ ) { 17 | userService.sample30Test(i); 18 | } 19 | } 20 | 21 | @Test 22 | public void rate50Test() { 23 | SampleRateServiceImpl userService = AutoLogProxy.getProxy(new SampleRateServiceImpl()); 24 | for(int i = 0; i < 10; i++ ) { 25 | userService.sample50Test(i); 26 | } 27 | } 28 | 29 | @Test 30 | public void rate100Test() { 31 | SampleRateServiceImpl userService = AutoLogProxy.getProxy(new SampleRateServiceImpl()); 32 | for(int i = 0; i < 10; i++ ) { 33 | userService.sample100Test(i); 34 | } 35 | } 36 | 37 | @Test 38 | public void rate0Test() { 39 | SampleRateServiceImpl userService = AutoLogProxy.getProxy(new SampleRateServiceImpl()); 40 | for(int i = 0; i < 10; i++ ) { 41 | userService.sample0Test(i); 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /auto-log-test/src/test/java/com/github/houbb/auto/log/core/bs/AutoLogBsTest.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.bs; 2 | 3 | import com.github.houbb.auto.log.core.support.proxy.AutoLogProxy; 4 | import com.github.houbb.auto.log.test.service.UserService; 5 | import com.github.houbb.auto.log.test.service.impl.ClassAnnotationService; 6 | import com.github.houbb.auto.log.test.service.impl.MenuServiceImpl; 7 | import com.github.houbb.auto.log.test.service.impl.DefineService; 8 | import com.github.houbb.auto.log.test.service.impl.UserServiceImpl; 9 | import org.junit.Test; 10 | 11 | /** 12 | * @author binbin.hou 13 | * @since 0.0.2 14 | */ 15 | public class AutoLogBsTest { 16 | 17 | @Test 18 | public void proxyTest() { 19 | UserService userService = AutoLogProxy.getProxy(new UserServiceImpl()); 20 | 21 | userService.queryLog("1"); 22 | } 23 | 24 | /** 25 | * 没有接口而测试 26 | * @since 0.0.5 27 | */ 28 | @Test 29 | public void proxyTest2() { 30 | MenuServiceImpl service = AutoLogProxy.getProxy(new MenuServiceImpl()); 31 | 32 | service.query("1"); 33 | } 34 | 35 | /** 36 | * 接口测试 TraceId 37 | * @since 0.0.8 38 | */ 39 | @Test 40 | public void proxyTestTraceId() { 41 | UserService service = AutoLogProxy.getProxy(new UserServiceImpl()); 42 | 43 | service.traceId("1"); 44 | } 45 | 46 | @Test 47 | public void classEnableTest() { 48 | ClassAnnotationService annotationService = AutoLogProxy.getProxy(new ClassAnnotationService()); 49 | annotationService.enable(); 50 | } 51 | 52 | @Test 53 | public void classDisableTest() { 54 | ClassAnnotationService annotationService = AutoLogProxy.getProxy(new ClassAnnotationService()); 55 | annotationService.disable(); 56 | } 57 | 58 | /** 59 | * 自定义拦截器 60 | * @since 0.0.10 61 | */ 62 | @Test 63 | public void myInterceptorTest() { 64 | DefineService service = AutoLogProxy.getProxy(new DefineService()); 65 | service.interceptor(); 66 | } 67 | 68 | /** 69 | * 自定义入参过滤器 70 | * @since 0.0.12 71 | */ 72 | @Test 73 | public void myFilterTest() { 74 | DefineService service = AutoLogProxy.getProxy(new DefineService()); 75 | service.paramFilter(); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /auto-log-test/src/test/java/com/github/houbb/auto/log/core/bs/AutoLogCoreDiscardTest.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.bs; 2 | 3 | import com.github.houbb.auto.log.core.support.proxy.AutoLogProxy; 4 | import com.github.houbb.auto.log.test.service.DiscardService; 5 | import com.github.houbb.auto.log.test.service.UserService; 6 | import com.github.houbb.auto.log.test.service.impl.ClassAnnotationService; 7 | import com.github.houbb.auto.log.test.service.impl.DefineService; 8 | import com.github.houbb.auto.log.test.service.impl.MenuServiceImpl; 9 | import com.github.houbb.auto.log.test.service.impl.UserServiceImpl; 10 | import org.junit.Test; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | /** 16 | * @author binbin.hou 17 | * @since 0.11.0 18 | */ 19 | public class AutoLogCoreDiscardTest { 20 | 21 | @Test 22 | public void discardTest() { 23 | DiscardService userService = AutoLogProxy.getProxy(new DiscardService()); 24 | 25 | List idList = new ArrayList<>(); 26 | for(int i = 0; i < 10000; i++) { 27 | idList.add("id-" + i); 28 | } 29 | 30 | userService.queryByIds(idList); 31 | } 32 | 33 | @Test 34 | public void maxLenTest() { 35 | DiscardService userService = AutoLogProxy.getProxy(new DiscardService()); 36 | userService.getString(10000); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /auto-log-test/src/test/java/com/github/houbb/auto/log/core/bs/package-info.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.core.bs; -------------------------------------------------------------------------------- /auto-log-test/src/test/java/com/github/houbb/auto/log/dynamic/SpringDynamicServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.dynamic; 2 | 3 | 4 | import com.github.houbb.auto.log.test.dynamic.SpringDynamicConfig; 5 | import com.github.houbb.auto.log.test.dynamic.service.MyAddressService; 6 | import com.github.houbb.auto.log.test.dynamic.service.MyUserService; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | 13 | /** 14 | * @author binbin.hou 15 | * @since 0.3.0 16 | */ 17 | @ContextConfiguration(classes = SpringDynamicConfig.class) 18 | @RunWith(SpringJUnit4ClassRunner.class) 19 | public class SpringDynamicServiceTest { 20 | 21 | @Autowired 22 | private MyAddressService myAddressService; 23 | 24 | @Autowired 25 | private MyUserService myUserService; 26 | 27 | @Test 28 | public void queryUserTest() { 29 | myUserService.queryUser("1"); 30 | } 31 | 32 | @Test 33 | public void queryAddressTest() { 34 | myAddressService.queryAddress("1"); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /auto-log-test/src/test/java/com/github/houbb/auto/log/spring/SpringPrivateServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.spring; 2 | 3 | 4 | import com.github.houbb.auto.log.test.config.SpringConfig; 5 | import com.github.houbb.auto.log.test.service.UserService; 6 | import com.github.houbb.auto.log.test.service.impl.PrivateUserServiceImpl; 7 | import com.github.houbb.heaven.util.lang.reflect.ReflectMethodUtil; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.test.context.ContextConfiguration; 12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 | 14 | import java.lang.reflect.InvocationTargetException; 15 | import java.lang.reflect.Method; 16 | 17 | /** 18 | * @author binbin.hou 19 | * @since 0.0.3 20 | */ 21 | @ContextConfiguration(classes = SpringConfig.class) 22 | @RunWith(SpringJUnit4ClassRunner.class) 23 | public class SpringPrivateServiceTest { 24 | 25 | @Autowired 26 | private PrivateUserServiceImpl privateUserService; 27 | 28 | @Test 29 | public void queryLogTest() { 30 | privateUserService.callPrivate(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /auto-log-test/src/test/java/com/github/houbb/auto/log/spring/SpringServiceMethodTest.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/houbb/auto-log/f482b512aba2e020e5fabfd75a1d549bb6f968af/auto-log-test/src/test/java/com/github/houbb/auto/log/spring/SpringServiceMethodTest.java -------------------------------------------------------------------------------- /auto-log-test/src/test/java/com/github/houbb/auto/log/spring/SpringServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.auto.log.spring; 2 | 3 | 4 | import com.github.houbb.auto.log.test.config.SpringConfig; 5 | import com.github.houbb.auto.log.test.service.UserService; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.test.context.ContextConfiguration; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | 12 | /** 13 | * @author binbin.hou 14 | * @since 0.0.3 15 | */ 16 | @ContextConfiguration(classes = SpringConfig.class) 17 | @RunWith(SpringJUnit4ClassRunner.class) 18 | public class SpringServiceTest { 19 | 20 | @Autowired 21 | private UserService userService; 22 | 23 | @Test 24 | public void queryLogTest() { 25 | userService.queryLog("1"); 26 | } 27 | 28 | @Test 29 | public void queryTest() { 30 | userService.query("1"); 31 | } 32 | 33 | @Test 34 | public void queryTraceIdTest() { 35 | userService.traceId("1"); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /auto-log-test/src/test/resources/META-INF/services/com.github.houbb.common.filter.api.CommonFilter: -------------------------------------------------------------------------------- 1 | com.github.houbb.auto.log.test.interceptor.MyAutoLogInterceptor -------------------------------------------------------------------------------- /cgit.bat: -------------------------------------------------------------------------------- 1 | :: 用于提交当前变更(windows) 2 | :: author: houbb 3 | :: LastUpdateTime: 2018-11-22 09:08:52 4 | :: 用法:双击运行,或者当前路径 cmd 直接输入 .\cgit.bat 5 | 6 | git pull 7 | git add . 8 | git commit -m "[Feature] add for new" 9 | git push 10 | git status 11 | 12 | -------------------------------------------------------------------------------- /cgit.sh: -------------------------------------------------------------------------------- 1 | # 提交 2 | 3 | git pull 4 | git add . 5 | git commit -m "[Feature] add for new" 6 | git push 7 | git status 8 | 9 | # 1. 赋值权限: chmod +x ./cgit.sh 10 | # 2. 执行: ./cgit.sh 11 | # Last Update Time: 2018-11-21 21:55:38 12 | # Author: houbb -------------------------------------------------------------------------------- /doc/02-dynamic-pointcut.md: -------------------------------------------------------------------------------- 1 | # 业务背景 2 | 3 | 很久以前开源了一款 [auto-log](https://github.com/houbb/auto-log) 自动日志打印框架。 4 | 5 | 其中对于 spring 项目,默认实现了基于 aop 切面的日志输出。 6 | 7 | 但是发现一个问题,如果切面定义为全切范围过大,于是 v0.2 版本就是基于注解 `@AutoLog` 实现的。 8 | 9 | 只有指定注解的类或者方法才会生效,但是这样使用起来很不方便。 10 | 11 | 如何才能动态指定 pointcut,让用户使用时可以自定义切面范围呢? 12 | 13 | # 自定义注解切面原理 14 | 15 | ## 常规 aop 方式 16 | 17 | ```java 18 | @Aspect 19 | @Component 20 | @EnableAspectJAutoProxy 21 | @Deprecated 22 | public class AutoLogAop { 23 | 24 | @Pointcut("@within(com.github.houbb.auto.log.annotation.AutoLog)" + 25 | "|| @annotation(com.github.houbb.auto.log.annotation.AutoLog)") 26 | public void autoLogPointcut() { 27 | } 28 | 29 | /** 30 | * 执行核心方法 31 | * 32 | * 相当于 MethodInterceptor 33 | * 34 | * @param point 切点 35 | * @return 结果 36 | * @throws Throwable 异常信息 37 | * @since 0.0.3 38 | */ 39 | @Around("autoLogPointcut()") 40 | public Object around(ProceedingJoinPoint point) throws Throwable { 41 | // 日志增强逻辑 42 | } 43 | 44 | } 45 | ``` 46 | 47 | 发现这里的 `@Pointcut` 注解属性是一个常量,无法方便地动态修改。 48 | 49 | 于是去查资料,找到了另一种更加灵活的方式。 50 | 51 | ## 可以指定 pointcut 的方式 52 | 53 | 我们通过 `@Value` 获取属性配置的切面值,给定默认值。这样用户就可以很方便的自定义。 54 | 55 | ```java 56 | /** 57 | * 动态配置的切面 58 | * 自动日志输出 aop 59 | * @author binbin.hou 60 | * @since 0.3.0 61 | */ 62 | @Configuration 63 | @Aspect 64 | //@EnableAspectJAutoProxy 65 | public class AutoLogDynamicPointcut { 66 | 67 | /** 68 | * 切面设置,直接和 spring 的配置对应 ${},可以从 properties 或者配置中心读取。更加灵活 69 | */ 70 | @Value("${auto.log.pointcut:@within(com.github.houbb.auto.log.annotation.AutoLog)||@annotation(com.github.houbb.auto.log.annotation.AutoLog)}") 71 | private String pointcut; 72 | 73 | @Bean("autoLogPointcutAdvisor") 74 | public AspectJExpressionPointcutAdvisor autoLogPointcutAdvisor() { 75 | AspectJExpressionPointcutAdvisor advisor = new AspectJExpressionPointcutAdvisor(); 76 | advisor.setExpression(pointcut); 77 | advisor.setAdvice(new AutoLogAdvice()); 78 | return advisor; 79 | } 80 | 81 | } 82 | ``` 83 | 84 | 当然,这里的 Advice 和以前的 aop 不同,需要重新进行实现。 85 | 86 | ### AutoLogAdvice 87 | 88 | 只需要实现 MethodInterceptor 接口即可。 89 | 90 | ```java 91 | /** 92 | * 切面拦截器 93 | * 94 | * @author binbin.hou 95 | * @since 0.3.0 96 | */ 97 | public class AutoLogAdvice implements MethodInterceptor { 98 | 99 | @Override 100 | public Object invoke(MethodInvocation methodInvocation) throws Throwable { 101 | // 增强逻辑 102 | } 103 | 104 | } 105 | ``` 106 | 107 | 介绍完了原理,我们一起来看下改进后的日志打印组件的效果。 108 | 109 | # spring 整合使用 110 | 111 | 完整示例参考 [SpringServiceTest](https://github.com/houbb/auto-log/tree/master/auto-log-test/src/test/java/com/github/houbb/auto/log/spring/SpringServiceTest.java) 112 | 113 | ## maven 引入 114 | 115 | ```xml 116 | 117 | com.github.houbb 118 | auto-log-spring 119 | 0.3.0 120 | 121 | ``` 122 | 123 | ## 注解声明 124 | 125 | 使用 `@EnableAutoLog` 启用自动日志输出 126 | 127 | ```java 128 | @Configurable 129 | @ComponentScan(basePackages = "com.github.houbb.auto.log.test.service") 130 | @EnableAutoLog 131 | public class SpringConfig { 132 | } 133 | ``` 134 | 135 | ## 测试代码 136 | 137 | ```java 138 | @ContextConfiguration(classes = SpringConfig.class) 139 | @RunWith(SpringJUnit4ClassRunner.class) 140 | public class SpringServiceTest { 141 | 142 | @Autowired 143 | private UserService userService; 144 | 145 | @Test 146 | public void queryLogTest() { 147 | userService.queryLog("1"); 148 | } 149 | 150 | } 151 | ``` 152 | 153 | - 输出结果 154 | 155 | ``` 156 | 信息: public java.lang.String com.github.houbb.auto.log.test.service.impl.UserServiceImpl.queryLog(java.lang.String) param is [1] 157 | 五月 30, 2020 12:17:51 下午 com.github.houbb.auto.log.core.support.interceptor.AutoLogMethodInterceptor info 158 | 信息: public java.lang.String com.github.houbb.auto.log.test.service.impl.UserServiceImpl.queryLog(java.lang.String) result is result-1 159 | 五月 30, 2020 12:17:51 下午 org.springframework.context.support.GenericApplicationContext doClose 160 | ``` 161 | 162 | ## 切面自定义 163 | 164 | ### 原理解释 165 | 166 | spring aop 的切面读取自 `@Value("${auto.log.pointcut}")`,默认为值 `@within(com.github.houbb.auto.log.annotation.AutoLog)||@annotation(com.github.houbb.auto.log.annotation.AutoLog)` 167 | 168 | 也就是默认是读取被 `@AutoLog` 指定的方法或者类。 169 | 170 | 当然,这并不够方便,我们希望可以想平时写 aop 注解一样,指定 spring aop 的扫描范围,直接在 spring 中指定一下 `auto.log.pointcut` 的属性值即可。 171 | 172 | ### 测试例子 173 | 174 | > [完整测试代码](https://github.com/houbb/auto-log/blob/master/auto-log-test/src/test/java/com/github/houbb/auto/log/dynamic/SpringDynamicServiceTest.java) 175 | 176 | 我们在配置文件 `autoLogConfig.properties` 中自定义下包扫描的范围: 177 | 178 | ``` 179 | auto.log.pointcut=execution(* com.github.houbb.auto.log.test.dynamic.service.MyAddressService.*(..)) 180 | ``` 181 | 182 | 自定义测试 service 183 | 184 | ```java 185 | package com.github.houbb.auto.log.test.dynamic.service; 186 | 187 | import org.springframework.stereotype.Service; 188 | 189 | @Service 190 | public class MyAddressService { 191 | 192 | public String queryAddress(String id) { 193 | return "address-" + id; 194 | } 195 | 196 | } 197 | ``` 198 | 199 | 自定义 spring 配置,指定我们定义的配置文件。springboot 啥的,可以直接放在 application.properties 中指定,此处仅作为演示。 200 | 201 | ```java 202 | @Configurable 203 | @ComponentScan(basePackages = "com.github.houbb.auto.log.test.dynamic.service") 204 | @EnableAutoLog 205 | @PropertySource("classpath:autoLogConfig.properties") 206 | public class SpringDynamicConfig { 207 | } 208 | ``` 209 | 210 | 测试 211 | 212 | ```java 213 | @ContextConfiguration(classes = SpringDynamicConfig.class) 214 | @RunWith(SpringJUnit4ClassRunner.class) 215 | public class SpringDynamicServiceTest { 216 | 217 | @Autowired 218 | private MyAddressService myAddressService; 219 | 220 | @Autowired 221 | private MyUserService myUserService; 222 | 223 | @Test 224 | public void queryUserTest() { 225 | // 不会被日志拦截 226 | myUserService.queryUser("1"); 227 | } 228 | 229 | @Test 230 | public void queryAddressTest() { 231 | // 会被日志拦截 232 | myAddressService.queryAddress("1"); 233 | } 234 | 235 | } 236 | ``` 237 | 238 | # 开源地址 239 | 240 | 为了便于大家学习,项目已开源。 241 | 242 | > Github: [https://github.com/houbb/auto-log](https://github.com/houbb/auto-log) 243 | 244 | > Gitee: [https://gitee.com/houbinbin/auto-log](https://gitee.com/houbinbin/auto-log) 245 | 246 | # 小结 247 | 248 | 这个项目很长一段时间拘泥于注解的方式,我个人用起来也不是很方便。 249 | 250 | 最近才想到了改进的方法,人还是要不断学习进步。 251 | 252 | 关于日志最近还学到了 aspect 的编译时增强,和基于 agent 的运行时增强,这 2 种方式都很有趣,有机会会做学习记录。 -------------------------------------------------------------------------------- /doc/CI集成.md: -------------------------------------------------------------------------------- 1 | # 文档说明 2 | 3 | 作者:侯宾宾 4 | 5 | 时间:2018-04-24 10:11:43 6 | 7 | 说明:如何进行项目的持续集成+测试覆盖率 8 | 9 | # Travis-CI 10 | 11 | [https://www.travis-ci.org](https://www.travis-ci.org) 直接添加此项目 12 | 13 | # Coveralls 14 | 15 | - 添加项目 16 | 17 | [https://coveralls.io/repos/new](https://coveralls.io/repos/new) 直接添加项目 18 | 19 | - 生成密匙 20 | 21 | ``` 22 | travis encrypt COVERALLS_TOKEN=${your_repo_token} 23 | ``` 24 | 25 | - 添加到文件 26 | 27 | ``` 28 | travis encrypt COVERALLS_TOKEN=${your_repo_token} --add 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /doc/issues/个人思考.md: -------------------------------------------------------------------------------- 1 | # 整体思路 2 | 3 | 不再强依赖 spring 4 | 5 | # 可参考实现 6 | 7 | https://github.com/sjlian/printparam-spring-boot-starter 8 | 9 | https://github.com/HAoDestiny/Proxy-AOP/blob/master/main/java/com/aop/prox/DynaProxy/DynaProxyTestLog.java 10 | 11 | https://github.com/k8nice/spring-aop-myannotation-log/blob/master/src/main/java/com/nice/config/SystemLogAspect.java 12 | 13 | https://github.com/yeszhjian/loglib 14 | -------------------------------------------------------------------------------- /doc/user/01-项目模块.md: -------------------------------------------------------------------------------- 1 | # api 2 | 3 | 核心接口 4 | 5 | # annotation 6 | 7 | 注解 8 | 9 | # core 10 | 11 | 核心接口实现 12 | 13 | # test 14 | 15 | 测试模块 16 | 17 | # 项目的演化 18 | 19 | 初期使用一个简单的 jar 20 | 21 | 后期如果有必要则进行模块拆分。 -------------------------------------------------------------------------------- /doc/发布流程.md: -------------------------------------------------------------------------------- 1 | # 文档说明 2 | 3 | 本文档用于说明当前项目如何进行发布。 4 | 5 | 6 | # 发布流程 7 | 8 | ## push to mvn center 9 | 10 | ``` 11 | mvn clean deploy -P release 12 | ``` 13 | 14 | ## commit to github 15 | 16 | ``` 17 | git push 18 | ``` 19 | 20 | ## merge to master 21 | 22 | ``` 23 | git checkout master 24 | git pull 25 | git checkout branch 26 | git rebase master (用rebase合并主干的修改,如果有冲突在此时解决) 27 | git checkout master 28 | git merge branch 29 | git push 30 | ``` 31 | 32 | ## create new branch & checkout 33 | 34 | ``` 35 | git branch release_XXX 36 | git checkout release_XXX 37 | ``` 38 | 39 | ## modify project version 40 | 41 | ``` 42 | mvn versions:set -DgroupId=com.github.houbb -DartifactId=paradise* -DoldVersion=1.1.2 -DnewVersion=1.1.3-SNAPSHOT--> 43 | mvn -N versions:update-child-modules 44 | mvn versions:commit 45 | ``` 46 | 47 | -------------------------------------------------------------------------------- /doc/版本迭代规范.md: -------------------------------------------------------------------------------- 1 | # 版本类型 2 | 3 | x.y.z 4 | 5 | x 表示大版本之间的迭代,可能出现前后的不兼容。 6 | 7 | y 表示新特性,每次新加一个新特性,都会提升 y 的版本号。 8 | 9 | z 表示修复版本号,如果为第一版,则 z=1。后续会依次提升。 10 | 11 | ## 使用的版本选择 12 | 13 | 如果在较为正式的环境使用,建议使用 x.y 相同,z 数值最大的版本。 14 | 15 | 因为这个版本为尽可能修复已知的 bug。 16 | 17 | ## 新特性 18 | 19 | 不同版本的新特性,参见变更日志。 20 | 21 | # 版本的兼容性 22 | 23 | 在同一个 x 大版本中,禁止直接删除类信息。 24 | 25 | 所有的废弃使用 `@Depretectd` 注解、 26 | 27 | ## 必须有对应的测试 28 | 29 | 对应的测试信息。 30 | 31 | 保证代码的正确性。 -------------------------------------------------------------------------------- /github_init.bat: -------------------------------------------------------------------------------- 1 | # github init 2 | git init 3 | git add * 4 | git commit -m "first commit" 5 | git remote add origin https://github.com/houbb/auto-log.git 6 | git push -u origin master -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 4.0.0 11 | 12 | com.github.houbb 13 | auto-log 14 | pom 15 | 0.12.0 16 | 17 | auto-log-annotation 18 | auto-log-core 19 | auto-log-core-extra 20 | auto-log-spring 21 | auto-log-springboot-starter 22 | auto-log-test 23 | 24 | 25 | 26 | 27 | 3.2 28 | 3.2 29 | 2.18.1 30 | true 31 | true 32 | 33 | 2.2.1 34 | 2.9.1 35 | 1.5 36 | 37 | 38 | UTF-8 39 | 1.7 40 | 41 | 42 | 0.8.0 43 | 1.1.8 44 | 0.0.4 45 | 0.0.1 46 | 0.0.7 47 | 0.11.0 48 | 1.4.0 49 | 1.0.0 50 | 51 | 52 | 4.12 53 | 1.5.22.RELEASE 54 | 4.3.15.RELEASE 55 | 1.2.83 56 | 2.7.7 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | com.github.houbb 65 | auto-log-annotation 66 | ${project.version} 67 | 68 | 69 | com.github.houbb 70 | auto-log-core 71 | ${project.version} 72 | 73 | 74 | com.github.houbb 75 | auto-log-core-extra 76 | ${project.version} 77 | 78 | 79 | com.github.houbb 80 | auto-log-spring 81 | ${project.version} 82 | 83 | 84 | com.github.houbb 85 | auto-log-springboot-starter 86 | ${project.version} 87 | 88 | 89 | 90 | 91 | com.github.houbb 92 | id-api 93 | ${id.version} 94 | 95 | 96 | com.github.houbb 97 | id-core 98 | ${id.version} 99 | 100 | 101 | 102 | com.github.houbb 103 | heaven 104 | ${heaven.version} 105 | 106 | 107 | com.github.houbb 108 | log-integration 109 | ${log-integration.version} 110 | 111 | 112 | com.github.houbb 113 | aop-core 114 | ${aop.version} 115 | 116 | 117 | com.github.houbb 118 | aop-spring 119 | ${aop.version} 120 | 121 | 122 | com.github.houbb 123 | test-spring 124 | ${test.version} 125 | 126 | 127 | com.github.houbb 128 | common-filter 129 | ${common-filter.version} 130 | 131 | 132 | com.github.houbb 133 | auto-trace-core 134 | ${auto-trace.version} 135 | 136 | 137 | com.github.houbb 138 | auto-trace-spring 139 | ${auto-trace.version} 140 | 141 | 142 | com.github.houbb 143 | mybatis-interceptor 144 | ${mybatis-interceptor.version} 145 | 146 | 147 | 148 | 149 | javax.servlet 150 | javax.servlet-api 151 | 3.0.1 152 | 153 | 154 | org.springframework.boot 155 | spring-boot-starter 156 | ${spring-boot.version} 157 | 158 | 159 | com.alibaba 160 | fastjson 161 | ${fastjson.version} 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | org.apache.maven.plugins 193 | maven-compiler-plugin 194 | ${plugin.compiler.version} 195 | 196 | ${project.compiler.level} 197 | ${project.compiler.level} 198 | ${project.build.sourceEncoding} 199 | 200 | 201 | 202 | 203 | org.apache.maven.plugins 204 | maven-surefire-plugin 205 | ${plugin.surefire.version} 206 | 207 | ${plugin.surefire.skip-it} 208 | ${plugin.surefire.ignore-failure} 209 | 210 | 211 | 212 | 213 | 214 | org.eluder.coveralls 215 | coveralls-maven-plugin 216 | 4.3.0 217 | 218 | 219 | 220 | org.codehaus.mojo 221 | cobertura-maven-plugin 222 | 2.7 223 | 224 | xml 225 | 256m 226 | 227 | true 228 | 229 | 230 | **/*Test.class 231 | **/HelpMojo.class 232 | **/*Vo.class 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | org.sonarsource.scanner.maven 242 | sonar-maven-plugin 243 | 3.1.1 244 | 245 | 246 | 247 | 248 | org.apache.maven.plugins 249 | maven-javadoc-plugin 250 | ${plugin.maven-javadoc-plugin.version} 251 | 252 | 253 | 254 | 255 | 256 | 257 | auto-log 258 | The auto-log tool for java. 259 | 260 | 261 | org.sonatype.oss 262 | oss-parent 263 | 7 264 | 265 | 266 | 267 | The Apache Software License, Version 2.0 268 | http://www.apache.org/licenses/LICENSE-2.0.txt 269 | repo 270 | 271 | 272 | 273 | https://github.com/houbb/auto-log 274 | https://github.com/houbb/auto-log.git 275 | https://houbb.github.io/ 276 | 277 | 278 | 279 | houbb 280 | houbinbin.echo@gmail.com 281 | https://houbb.github.io/ 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | release 290 | 291 | 292 | 293 | 294 | org.apache.maven.plugins 295 | maven-source-plugin 296 | ${plugin.maven-source-plugin.version} 297 | 298 | 299 | package 300 | 301 | jar-no-fork 302 | 303 | 304 | 305 | 306 | 307 | 308 | org.apache.maven.plugins 309 | maven-javadoc-plugin 310 | ${plugin.maven-javadoc-plugin.version} 311 | 312 | 313 | package 314 | 315 | jar 316 | 317 | 318 | 319 | 320 | 321 | 322 | org.apache.maven.plugins 323 | maven-gpg-plugin 324 | ${plugin.maven-gpg-plugin.version} 325 | 326 | 327 | verify 328 | 329 | sign 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | oss 339 | https://oss.sonatype.org/content/repositories/snapshots/ 340 | 341 | 342 | oss 343 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 344 | 345 | 346 | 347 | 348 | 349 | 350 | -------------------------------------------------------------------------------- /release.bat: -------------------------------------------------------------------------------- 1 | :: 用于 release 当前项目(windows) 2 | :: author: houbb 3 | :: LastUpdateTime: 2018-1-22 09:08:52 4 | :: 用法:双击运行,或者当前路径 cmd 直接输入 release.bat 5 | 6 | :: 关闭回显 7 | @echo OFF 8 | 9 | ECHO "============================= RELEASE START..." 10 | 11 | :: 版本号信息(需要手动指定) 12 | :::: 旧版本名称 13 | SET version=0.12.0 14 | :::: 新版本名称 15 | SET newVersion=0.13.0 16 | :::: 组织名称 17 | SET groupName=com.github.houbb 18 | :::: 项目名称 19 | SET projectName=auto-log 20 | 21 | :: release 项目版本 22 | :::: snapshot 版本号 23 | SET snapshot_version=%version%"-SNAPSHOT" 24 | :::: 新的版本号 25 | SET release_version=%version% 26 | 27 | call mvn versions:set -DgroupId=%groupName% -DartifactId=%projectName% -DoldVersion=%snapshot_version% -DnewVersion=%release_version% 28 | call mvn -N versions:update-child-modules 29 | call mvn versions:commit 30 | call echo "1. RELEASE %snapshot_version% TO %release_version% DONE." 31 | 32 | 33 | :: 推送到 github 34 | git add . 35 | git commit -m "release branch %version%" 36 | git push 37 | git status 38 | 39 | ECHO "2. PUSH TO GITHUB DONE." 40 | 41 | :: 推送到 maven 中央仓库 42 | call mvn clean deploy -P release 43 | ECHO "3 PUSH TO MVN CENTER DONE." 44 | -------------------------------------------------------------------------------- /release.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | echo "============================= RELEASE START..." 3 | 4 | ## 版本号信息(需要手动指定) 5 | version="0.0.1" 6 | newVersion="0.0.2" 7 | projectName="csv" 8 | 9 | # release 项目版本 10 | ## snapshot 版本号 11 | snapshot_version=${version}"-SNAPSHOT" 12 | ## 新的版本号 13 | release_version=${version} 14 | 15 | mvn versions:set -DgroupId=com.github.houbb -DartifactId=${projectName} -DoldVersion=${snapshot_version} -DnewVersion=${release_version} 16 | mvn -N versions:update-child-modules 17 | mvn versions:commit 18 | echo "1. RELEASE ${snapshot_version} TO ${release_version} DONE." 19 | 20 | 21 | # 推送到 github 22 | git add . 23 | git commit -m "release branch ${version}" 24 | git push 25 | git status 26 | 27 | echo "2. PUSH TO GITHUB DONE." 28 | 29 | 30 | # 推送到 maven 中央仓库 31 | mvn clean deploy -P release 32 | 33 | echo "3. PUSH TO MAVEN CENTER DONE." 34 | 35 | # 合并到 master 分支 36 | branchName="release_"${version} # 分支名称 37 | git checkout master 38 | git pull 39 | git checkout ${branchName} 40 | git rebase master 41 | git checkout master 42 | git merge ${branchName} 43 | git push 44 | 45 | echo "4. MERGE TO MASTER DONE." 46 | 47 | 48 | # 拉取新的分支 49 | newBranchName="release_"${newVersion} 50 | git branch ${newBranchName} 51 | git checkout ${newBranchName} 52 | git push --set-upstream origin ${newBranchName} 53 | 54 | echo "5. NEW BRANCH DONE." 55 | 56 | # 修改新分支的版本号 57 | ## snapshot 版本号 58 | snapshot_new_version=${newVersion}"-SNAPSHOT" 59 | mvn versions:set -DgroupId=com.github.houbb -DartifactId=${projectName} -DoldVersion=${release_version} -DnewVersion=${snapshot_new_version} 60 | mvn -N versions:update-child-modules 61 | mvn versions:commit 62 | 63 | git add . 64 | git commit -m "modify branch ${release_version} TO ${snapshot_new_version}" 65 | git push 66 | git status 67 | echo "6. MODIFY ${release_version} TO ${snapshot_new_version} DONE." 68 | 69 | echo "============================= RELEASE END..." 70 | 71 | 72 | # 使用方式: 73 | # 1. 赋值权限: chmod +x ./release.sh 74 | # 2. 执行: ./release.sh 75 | # Last Update Time: 2018-01-20 13:17:06 76 | # Author: houbb 77 | 78 | 79 | -------------------------------------------------------------------------------- /release_rm.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | echo "============================= RELEASE START..." 3 | 4 | ## 版本号信息(需要手动指定) 5 | oldVersion="1.0.0" 6 | newVersion="1.0.0" 7 | projectName="csv" 8 | 9 | # 删除分支 10 | oldBranchName="release_"${oldVersion} 11 | git branch -d ${oldBranchName} 12 | git push origin --delete ${oldBranchName} 13 | 14 | echo "1. Branch remove success..." 15 | 16 | # 拉取新的分支 17 | newBranchName="release_"${newVersion} 18 | git branch ${newBranchName} 19 | git checkout ${newBranchName} 20 | git push --set-upstream origin ${newBranchName} 21 | 22 | echo "2. NEW BRANCH DONE." 23 | 24 | # 修改新分支的版本号 25 | ## snapshot 版本号 26 | snapshot_new_version=${newVersion}"-SNAPSHOT" 27 | mvn versions:set -DgroupId=com.github.houbb -DartifactId=${projectName} -DoldVersion=${release_version} -DnewVersion=${snapshot_new_version} 28 | mvn -N versions:update-child-modules 29 | mvn versions:commit 30 | 31 | git add . 32 | git commit -m "modify branch ${release_version} TO ${snapshot_new_version}" 33 | git push 34 | git status 35 | echo "3. MODIFY ${release_version} TO ${snapshot_new_version} DONE." 36 | 37 | echo "============================= BRANCH RE-CREATE END..." 38 | 39 | echo "============================= BRANCH LIST =============================" 40 | git branch -a 41 | 42 | # 使用方式: 43 | # 注意:本脚本用于删除分支,谨慎使用! 44 | # 1. 赋值权限: chmod +x ./release_rm.sh 45 | # 2. 执行: ./release_rm.sh 46 | # Last Update Time: 2018-06-21 11:10:42 47 | # Author: houbb --------------------------------------------------------------------------------