Skip to content

Commit bed7d04

Browse files
authored
refactor: Remove unused charset setting from log configuration (#597)
1 parent 410efd4 commit bed7d04

File tree

13 files changed

+51
-209
lines changed

13 files changed

+51
-209
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ If applicable, add screenshots to help explain your problem.
4848
```
4949

5050
2. Console output `easy_api`
51-
- Please set <kbd>Preferences(Settings)</kbd> > <kbd>Other Settings</kbd> > <kbd>EasyApi</kbd> > <kbd> Common</kbd> > <kbd>log</kbd> to `LOW```
51+
- Please set <kbd>Preferences(Settings)</kbd> > <kbd>Other Settings</kbd> > <kbd>EasyApi</kbd> > <kbd> Common</kbd> > <kbd>log</kbd> to `VERBOSE```
5252

5353
3. Logs of IDEA: <br>
5454
The easiest way to find the product log file is the Help menu, the item name would depend on the IDE version and OS:- Show Log in Explorer

idea-plugin/src/main/kotlin/com/itangcent/debug/LoggerCollector.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.itangcent.debug
22

3+
import com.itangcent.debug.LoggerCollector.Companion.buffer
34
import com.itangcent.intellij.logger.AbstractLogger
45
import com.itangcent.intellij.logger.Logger
56

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/actions/BasicAnAction.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import com.itangcent.common.spi.Setup
66
import com.itangcent.common.spi.SpiUtils
77
import com.itangcent.idea.config.CachedResourceResolver
88
import com.itangcent.idea.plugin.Initializer
9-
import com.itangcent.idea.plugin.log.CustomLogConfig
109
import com.itangcent.idea.utils.ConfigurableLogger
1110
import com.itangcent.intellij.actions.KotlinAnAction
1211
import com.itangcent.intellij.config.resource.ResourceResolver
@@ -16,7 +15,6 @@ import com.itangcent.intellij.extend.guice.singleton
1615
import com.itangcent.intellij.extend.guice.with
1716
import com.itangcent.intellij.jvm.kotlin.KotlinAutoInject
1817
import com.itangcent.intellij.logger.IdeaConsoleLogger
19-
import com.itangcent.intellij.logger.LogConfig
2018
import com.itangcent.intellij.logger.Logger
2119
import com.itangcent.intellij.spi.IdeaAutoInject
2220
import com.itangcent.intellij.tip.OnlyOnceInContextTipSetup
@@ -35,10 +33,10 @@ abstract class BasicAnAction : KotlinAnAction {
3533
override fun onBuildActionContext(event: AnActionEvent, builder: ActionContextBuilder) {
3634

3735
super.onBuildActionContext(event, builder)
38-
builder.bind(LogConfig::class) { it.with(CustomLogConfig::class).singleton() }
3936

4037
builder.bind(Logger::class) { it.with(ConfigurableLogger::class).singleton() }
4138
builder.bind(Logger::class, "delegate.logger") { it.with(IdeaConsoleLogger::class).singleton() }
39+
4240
builder.bind(ResourceResolver::class) { it.with(CachedResourceResolver::class).singleton() }
4341

4442
afterBuildActionContext(event, builder)

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/EasyApiSettingGUI.form

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<properties/>
2727
<border type="none" title="Common"/>
2828
<children>
29-
<grid id="4b407" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
29+
<grid id="4b407" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
3030
<margin top="0" left="0" bottom="0" right="0"/>
3131
<constraints>
3232
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="2" indent="0" use-parent-layout="false"/>
@@ -37,7 +37,7 @@
3737
<grid id="e66ee" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
3838
<margin top="0" left="0" bottom="0" right="0"/>
3939
<constraints>
40-
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="8" fill="2" indent="0" use-parent-layout="false">
40+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="2" indent="0" use-parent-layout="false">
4141
<minimum-size width="310" height="-1"/>
4242
<preferred-size width="310" height="-1"/>
4343
<maximum-size width="310" height="-1"/>
@@ -80,42 +80,6 @@
8080
</grid>
8181
</children>
8282
</grid>
83-
<grid id="51c22" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
84-
<margin top="0" left="0" bottom="0" right="0"/>
85-
<constraints>
86-
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="2" indent="0" use-parent-layout="false">
87-
<minimum-size width="310" height="-1"/>
88-
<preferred-size width="310" height="-1"/>
89-
<maximum-size width="310" height="-1"/>
90-
</grid>
91-
</constraints>
92-
<properties/>
93-
<border type="none"/>
94-
<children>
95-
<component id="f845" class="javax.swing.JLabel">
96-
<constraints>
97-
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
98-
<minimum-size width="90" height="-1"/>
99-
<preferred-size width="90" height="-1"/>
100-
<maximum-size width="90" height="-1"/>
101-
</grid>
102-
</constraints>
103-
<properties>
104-
<text value="charset:"/>
105-
</properties>
106-
</component>
107-
<component id="90b9a" class="javax.swing.JComboBox" binding="logCharsetComboBox">
108-
<constraints>
109-
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="0" indent="0" use-parent-layout="false">
110-
<minimum-size width="160" height="-1"/>
111-
<preferred-size width="160" height="-1"/>
112-
<maximum-size width="160" height="-1"/>
113-
</grid>
114-
</constraints>
115-
<properties/>
116-
</component>
117-
</children>
118-
</grid>
11983
</children>
12084
</grid>
12185
</children>

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/EasyApiSettingGUI.kt

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.itangcent.idea.plugin.dialog
22

33
import com.google.inject.Inject
4-
import com.intellij.openapi.project.Project
54
import com.intellij.openapi.ui.ComboBoxTableRenderer
65
import com.intellij.openapi.util.text.StringUtil
76
import com.intellij.ui.MutableCollectionComboBoxModel
@@ -44,9 +43,6 @@ class EasyApiSettingGUI : AbstractEasyApiSettingGUI() {
4443
@Inject
4544
private lateinit var actionContext: ActionContext
4645

47-
@Inject(optional = true)
48-
private var myProject: Project? = null
49-
5046
private var rootPanel: JPanel? = null
5147

5248
//region postman-----------------------------------------------------
@@ -105,8 +101,6 @@ class EasyApiSettingGUI : AbstractEasyApiSettingGUI() {
105101

106102
private var logLevelComboBox: JComboBox<Logger.Level>? = null
107103

108-
private var logCharsetComboBox: JComboBox<Charsets>? = null
109-
110104
private var methodDocEnableCheckBox: JCheckBox? = null
111105

112106
private var genericEnableCheckBox: JCheckBox? = null
@@ -178,10 +172,10 @@ class EasyApiSettingGUI : AbstractEasyApiSettingGUI() {
178172
SwingUtils.immersed(this.postmanWorkSpaceRefreshButton!!)
179173

180174
postmanJson5FormatTypeComboBox!!.model =
181-
DefaultComboBoxModel(PostmanJson5FormatType.values().mapToTypedArray { it.name })
175+
DefaultComboBoxModel(PostmanJson5FormatType.entries.mapToTypedArray { it.name })
182176

183177
postmanExportModeComboBox!!.model =
184-
DefaultComboBoxModel(PostmanExportMode.values().mapToTypedArray { it.name })
178+
DefaultComboBoxModel(PostmanExportMode.entries.mapToTypedArray { it.name })
185179

186180
this.postmanTokenTextField!!.onTextChange {
187181
postmanWorkSpaceRefreshButton!!.isVisible = it.notNullOrBlank()
@@ -196,7 +190,7 @@ class EasyApiSettingGUI : AbstractEasyApiSettingGUI() {
196190
}
197191

198192
postmanCollectionsRefreshButton!!.addActionListener {
199-
refreshPostmanCollections(false)
193+
forceRefreshPostmanCollections()
200194
}
201195

202196
postmanTokenLabel!!.addMouseListener(object : MouseAdapter() {
@@ -221,17 +215,15 @@ class EasyApiSettingGUI : AbstractEasyApiSettingGUI() {
221215
clearProjectCache()
222216
}
223217

224-
logLevelComboBox!!.model = DefaultComboBoxModel(CommonSettingsHelper.CoarseLogLevel.editableValues())
225-
226-
logCharsetComboBox!!.model = DefaultComboBoxModel(Charsets.SUPPORTED_CHARSETS)
218+
logLevelComboBox!!.model = DefaultComboBoxModel(CommonSettingsHelper.VerbosityLevel.editableValues())
227219

228220
outputCharsetComboBox!!.model = DefaultComboBoxModel(Charsets.SUPPORTED_CHARSETS)
229221

230222
markdownFormatTypeComboBox!!.model =
231-
DefaultComboBoxModel(MarkdownFormatType.values().mapToTypedArray { it.name })
223+
DefaultComboBoxModel(MarkdownFormatType.entries.mapToTypedArray { it.name })
232224

233225
httpClientComboBox!!.model =
234-
DefaultComboBoxModel(HttpClientType.values().mapToTypedArray { it.value })
226+
DefaultComboBoxModel(HttpClientType.entries.mapToTypedArray { it.value })
235227

236228
//endregion general-----------------------------------------------------
237229
}
@@ -246,8 +238,7 @@ class EasyApiSettingGUI : AbstractEasyApiSettingGUI() {
246238
this.buildExampleCheckBox!!.isSelected = settings.postmanBuildExample
247239

248240
this.postmanWorkspaceComboBoxModel?.selectedItem = this.selectedPostmanWorkspace
249-
this.logLevelComboBox!!.selectedItem = CommonSettingsHelper.CoarseLogLevel.toLevel(settings.logLevel)
250-
this.logCharsetComboBox!!.selectedItem = Charsets.forName(settings.logCharset)
241+
this.logLevelComboBox!!.selectedItem = CommonSettingsHelper.VerbosityLevel.toLevel(settings.logLevel)
251242
this.outputCharsetComboBox!!.selectedItem = Charsets.forName(settings.outputCharset)
252243
this.postmanJson5FormatTypeComboBox!!.selectedItem = settings.postmanJson5FormatType
253244
this.postmanExportModeComboBox!!.selectedItem = settings.postmanExportMode
@@ -289,13 +280,13 @@ class EasyApiSettingGUI : AbstractEasyApiSettingGUI() {
289280

290281
try {
291282
computeGlobalCacheSize()
292-
} catch (e: Exception) {
283+
} catch (_: Exception) {
293284
//ignore
294285
}
295286

296287
try {
297288
computeProjectCacheSize()
298-
} catch (e: Exception) {
289+
} catch (_: Exception) {
299290
//ignore
300291
}
301292
}
@@ -333,15 +324,10 @@ class EasyApiSettingGUI : AbstractEasyApiSettingGUI() {
333324
private var tableMouseListener: MouseListener? = null
334325
private var postmanCollectionInit = false
335326

336-
337327
@Synchronized
338-
private fun refreshPostmanCollections(cache: Boolean) {
339-
if (cache) {
328+
private fun forceRefreshPostmanCollections() {
329+
postmanCachedApiHelper.withoutCache {
340330
refreshPostmanCollections()
341-
} else {
342-
postmanCachedApiHelper.withoutCache {
343-
refreshPostmanCollections()
344-
}
345331
}
346332
}
347333

@@ -565,9 +551,7 @@ class EasyApiSettingGUI : AbstractEasyApiSettingGUI() {
565551
settings.httpClient = httpClientComboBox!!.selectedItem as? String ?: HttpClientType.APACHE.value
566552
settings.httpTimeOut = httpTimeOutTextField!!.text.toIntOrNull() ?: 10
567553
settings.useRecommendConfig = recommendedCheckBox!!.isSelected
568-
settings.logLevel =
569-
(logLevelComboBox!!.selected() ?: CommonSettingsHelper.CoarseLogLevel.LOW).getLevel()
570-
settings.logCharset = (logCharsetComboBox!!.selectedItem as? Charsets ?: Charsets.UTF_8).displayName()
554+
settings.logLevel = (logLevelComboBox!!.selected() ?: CommonSettingsHelper.VerbosityLevel.NORMAL).getLevel()
571555
settings.outputDemo = outputDemoCheckBox!!.isSelected
572556
settings.outputCharset = (outputCharsetComboBox!!.selectedItem as? Charsets ?: Charsets.UTF_8).displayName()
573557
settings.markdownFormatType =

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/log/CustomLogConfig.kt

Lines changed: 0 additions & 22 deletions
This file was deleted.

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/Settings.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,12 @@ class Settings : ProjectSettingsSupport, ApplicationSettingsSupport {
8080
/**
8181
* Charset for output file
8282
*/
83-
override var logCharset: String = Charsets.UTF_8.displayName()
83+
override var outputCharset: String = Charsets.UTF_8.displayName()
8484

8585
// markdown
8686

8787
override var outputDemo: Boolean = true
8888

89-
/**
90-
* Charset for out put file
91-
*/
92-
override var outputCharset: String = Charsets.UTF_8.displayName()
93-
9489
override var markdownFormatType: String = MarkdownFormatType.SIMPLE.name
9590

9691
override var builtInConfig: String? = null
@@ -187,7 +182,6 @@ class Settings : ProjectSettingsSupport, ApplicationSettingsSupport {
187182
if (useRecommendConfig != other.useRecommendConfig) return false
188183
if (recommendConfigs != other.recommendConfigs) return false
189184
if (logLevel != other.logLevel) return false
190-
if (logCharset != other.logCharset) return false
191185
if (outputDemo != other.outputDemo) return false
192186
if (outputCharset != other.outputCharset) return false
193187
if (markdownFormatType != other.markdownFormatType) return false
@@ -235,7 +229,6 @@ class Settings : ProjectSettingsSupport, ApplicationSettingsSupport {
235229
result = 31 * result + useRecommendConfig.hashCode()
236230
result = 31 * result + recommendConfigs.hashCode()
237231
result = 31 * result + logLevel
238-
result = 31 * result + logCharset.hashCode()
239232
result = 31 * result + outputDemo.hashCode()
240233
result = 31 * result + outputCharset.hashCode()
241234
result = 31 * result + markdownFormatType.hashCode()
@@ -265,7 +258,7 @@ class Settings : ProjectSettingsSupport, ApplicationSettingsSupport {
265258
"readSetter=$readSetter, inferEnable=$inferEnable, inferMaxDeep=$inferMaxDeep, " +
266259
"selectedOnly=$selectedOnly, httpTimeOut=$httpTimeOut, trustHosts=${trustHosts.contentToString()}, " +
267260
"unsafeSsl=$unsafeSsl, httpClient='$httpClient', useRecommendConfig=$useRecommendConfig, " +
268-
"recommendConfigs='$recommendConfigs', logLevel=$logLevel, logCharset='$logCharset', " +
261+
"recommendConfigs='$recommendConfigs', logLevel=$logLevel, " +
269262
"outputDemo=$outputDemo, outputCharset='$outputCharset', markdownFormatType='$markdownFormatType', " +
270263
"builtInConfig=$builtInConfig, remoteConfig=${remoteConfig.contentToString()}, " +
271264
"aiProvider=$aiProvider, " +

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/helper/CommonSettingsHelper.kt

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,20 @@ class CommonSettingsHelper {
2121
return settingBinder.read().logLevel
2222
}
2323

24-
fun logCharset(): Charset {
25-
return Charsets.forName(settingBinder.read().logCharset)?.charset() ?: kotlin.text.Charsets.UTF_8
26-
}
27-
2824
fun currentLogLevel(): Logger.Level {
2925
val logLevel: Int = logLevel()
30-
return logLevel.let { CoarseLogLevel.toLevel(it) }
26+
return logLevel.let { VerbosityLevel.toLevel(it) }
3127
}
3228

33-
enum class CoarseLogLevel : Logger.Level {
29+
enum class VerbosityLevel : Logger.Level {
3430
EMPTY(1000) {
3531
override fun getLevelStr(): String {
3632
return ""
3733
}
3834
},
39-
LOW(50),
40-
MEDIUM(250),
41-
HIGH(450)
35+
VERBOSE(50),
36+
NORMAL(250),
37+
QUIET(450)
4238
;
4339

4440
private val level: Int
@@ -48,7 +44,7 @@ class CommonSettingsHelper {
4844
}
4945

5046
override fun getLevelStr(): String {
51-
throw UnsupportedOperationException("CoarseLogLevel only be used as level")
47+
throw UnsupportedOperationException("VerbosityLevel only be used as level")
5248
}
5349

5450
override fun getLevel(): Int {
@@ -62,25 +58,25 @@ class CommonSettingsHelper {
6258
companion object {
6359

6460
fun toLevel(level: Int): Logger.Level {
65-
return toLevel(level, LOW)
61+
return toLevel(level, VERBOSE)
6662
}
6763

6864
fun toLevel(level: Int, defaultLevel: Logger.Level): Logger.Level {
6965
return when (level) {
70-
LOW.level -> LOW
71-
MEDIUM.level -> MEDIUM
72-
HIGH.level -> HIGH
66+
VERBOSE.level -> VERBOSE
67+
NORMAL.level -> NORMAL
68+
QUIET.level -> QUIET
7369
else -> Logger.BasicLevel.toLevel(level, defaultLevel)
7470
}
7571
}
7672

77-
fun editableValues(): Array<CoarseLogLevel> {
78-
return values().filter { it != EMPTY }.toTypedArray()
73+
fun editableValues(): Array<VerbosityLevel> {
74+
return entries.filter { it != EMPTY }.toTypedArray()
7975
}
8076
}
8177
}
8278
}
8379

8480
fun CommonSettingsHelper?.currentLogLevel(): Logger.Level {
85-
return this?.currentLogLevel() ?: CommonSettingsHelper.CoarseLogLevel.LOW
81+
return this?.currentLogLevel() ?: CommonSettingsHelper.VerbosityLevel.VERBOSE
8682
}

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/settings/xml/ApplicationSettings.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ interface ApplicationSettingsSupport {
3535
var useRecommendConfig: Boolean
3636
var recommendConfigs: String
3737
var logLevel: Int
38-
var logCharset: String
3938
var outputDemo: Boolean
4039
var outputCharset: String
4140
var markdownFormatType: String
@@ -80,7 +79,6 @@ interface ApplicationSettingsSupport {
8079
newSetting.useRecommendConfig = this.useRecommendConfig
8180
newSetting.recommendConfigs = this.recommendConfigs
8281
newSetting.logLevel = this.logLevel
83-
newSetting.logCharset = this.logCharset
8482
newSetting.outputDemo = this.outputDemo
8583
newSetting.outputCharset = this.outputCharset
8684
newSetting.markdownFormatType = this.markdownFormatType
@@ -164,13 +162,6 @@ class ApplicationSettings : ApplicationSettingsSupport {
164162

165163
override var logLevel: Int = 50
166164

167-
/**
168-
* Charset for out put file
169-
*/
170-
override var logCharset: String = Charsets.UTF_8.displayName()
171-
172-
// markdown
173-
174165
override var outputDemo: Boolean = true
175166

176167
override var outputCharset: String = Charsets.UTF_8.displayName()

0 commit comments

Comments
 (0)