Add configuration for local env(#861)
-
也判断下是不是 Eclipse 启动的(判断下是否能加载到 Eclipse 的 class) Eclipse 似乎并不是像 IDEA 一样使用 agent 方式启动,所以没有找到 Eclipse 的 class,参考了一些资料How to detect that code is running inside eclipse IDE,没有找到比较靠谱的判断方式,所以没有实现该功能
-
加个配置项,如果配了就认为是通过 IDE 启动的 增加了相关的配置项与其对应的测试类
Hi @aaronlinv, welcome to SOFAStack community, Please sign Contributor License Agreement!
After you signed CLA, we will automatically sync the status of this pull request in 3 minutes.
Thanks for your contribution! @alaneuler Can u help review this pr ?
@aaronlinv
- plz format the code via
mvn package - we want a configuration for specifying local env, not logging (
isLocalEnvreturnstrueif setting the configuration to true) - set aside the eclipse detecting as there seems no reliable way of detecting
@alaneuler
Thanks, only need to detect the specified environment variable in the isLocalEnv method?
@alaneuler Thanks, only need to detect the specified environment variable in the
isLocalEnvmethod?
To put it simple, say, users of SOFABoot add a configuration item sofa.local.env=true (just for example, you can decide the key sensibly) in application.properties, then method isLocalEnv always returns true no matter if it runs in Eclipse/IntelliJ IDEA or not.
-
There is no need to modify
LogEnvironmentPrepareingListener#defaultConsoleLoggers() -
sofa.local.env=trueshould be read and instantiateLocalEnvUtilfield -
when use
LocalEnvUtil#isLocalEnv,- first you shoud read this field
- if this field is null you should assert runs in Eclipse/IntelliJ IDEA or not.
-
reason
- this
LocalEnvUtilnot only used inLogEnvironmentPrepareingListener,this is a universal static method ,- example
- if
LocalEnvUtil#isLocalEnvreturntrue, allows you to do things that are not allowed in the production environment.
- if
- example
- this
-
important
- you should instantiate this
sofa.local.env=trueto LocalEnvUtil BeforeLogEnviromnetPrepareingListener#defaultConsoleLoggers()
- you should instantiate this
Thanks, all very helpful, I resubmitted the code, is this ok?
Codecov Report
Merging #877 (5c1fec3) into master (b3770f2) will increase coverage by
0.57%. The diff coverage is16.66%.
:exclamation: Current head 5c1fec3 differs from pull request most recent head 2e22741. Consider uploading reports for the commit 2e22741 to get more accurate results
@@ Coverage Diff @@
## master #877 +/- ##
============================================
+ Coverage 71.15% 71.72% +0.57%
Complexity 36 36
============================================
Files 303 301 -2
Lines 8601 8514 -87
Branches 1195 1177 -18
============================================
- Hits 6120 6107 -13
+ Misses 1794 1723 -71
+ Partials 687 684 -3
| Impacted Files | Coverage Δ | |
|---|---|---|
| ...ava/com/alipay/sofa/boot/logging/LocalEnvUtil.java | 35.71% <16.66%> (-14.29%) |
:arrow_down: |
| ...ipay/sofa/runtime/api/ServiceRuntimeException.java | 0.00% <0.00%> (-25.00%) |
:arrow_down: |
| ...a/runtime/component/impl/ComponentManagerImpl.java | 60.18% <0.00%> (-2.78%) |
:arrow_down: |
| ...pay/sofa/runtime/SofaBizUninstallEventHandler.java | 64.28% <0.00%> (-2.39%) |
:arrow_down: |
| ...fa/runtime/service/component/ServiceComponent.java | 56.16% <0.00%> (-2.28%) |
:arrow_down: |
| ...y/sofa/runtime/invoke/JvmServiceTargetHabitat.java | ||
| ...fa/runtime/spring/AfterBizStartupEventHandler.java | ||
| ...com/alipay/sofa/runtime/SofaRuntimeProperties.java | 80.00% <0.00%> (+0.83%) |
:arrow_up: |
| ...m/alipay/sofa/isle/stage/ModuleLogOutputStage.java | 94.93% <0.00%> (+2.53%) |
:arrow_up: |
| .../configure/SofaRuntimeConfigurationProperties.java | 96.87% <0.00%> (+7.40%) |
:arrow_up: |
| ... and 2 more |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update b3770f2...2e22741. Read the comment docs.
LocalEnvUtil 是作为静态类使用的,目前这种写法是无法注入配置的,你还有时间修复这段代码吗?
LocalEnvUtil 是作为静态类使用的,目前这种写法是无法注入配置的,你还有时间修复这段代码吗?
非常抱歉,目前在忙其他的事情,没有时间修复,请将对应的 issue 分配给其他的小伙伴