Skip to content

Commit 7efc3cd

Browse files
committed
Let user pick the log level for the language server
Signed-off-by: BoykoAlex <[email protected]>
1 parent 95998d7 commit 7efc3cd

File tree

11 files changed

+115
-47
lines changed

11 files changed

+115
-47
lines changed

eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/STS4LanguageServerProcessStreamConnector.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public abstract class STS4LanguageServerProcessStreamConnector extends ProcessSt
4949
private String connectorId;
5050

5151
public STS4LanguageServerProcessStreamConnector(ServerInfo server) {
52-
this.connectorId = server.bundleId;
52+
this.connectorId = server.bundleId();
5353
this.consoles = LanguageServerConsoles.getConsoleFactory(server);
5454
}
5555

@@ -135,13 +135,14 @@ private void fillCommand(List<String> command, List<String> extraVmArgs) {
135135

136136
LsPreferencesUtil.getServerInfo(getPluginId()).ifPresent(info -> {
137137
IPreferenceStore preferenceStore = LanguageServerCommonsActivator.getInstance().getPreferenceStore();
138-
if (!preferenceStore.getBoolean(info.preferenceKeyConsoleLog)) {
139-
String pathStr = preferenceStore.getString(info.preferenceKeyFileLog);
138+
if (!preferenceStore.getBoolean(info.preferenceKeyConsoleLog())) {
139+
String pathStr = preferenceStore.getString(info.preferenceKeyFileLog());
140140
if (pathStr != null && !pathStr.isBlank()) {
141141
command.add("-Dsts.log.file=" + pathStr);
142142
}
143143
}
144-
command.add("-XX:ErrorFile=" + Platform.getStateLocation(Platform.getBundle(getPluginId())).append("fatal-error-" + info.label.replaceAll("\\s+", "-").toLowerCase() + "_" + System.currentTimeMillis()));
144+
command.add("-Dlogging.level.root=" + preferenceStore.getString(info.preferenceKeyLogLevel()));
145+
command.add("-XX:ErrorFile=" + Platform.getStateLocation(Platform.getBundle(getPluginId())).append("fatal-error-" + info.label().replaceAll("\\s+", "-").toLowerCase() + "_" + System.currentTimeMillis()));
145146
});
146147

147148
command.add("-Dlanguageserver.hover-timeout=225");

eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/console/LanguageServerConsoles.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ public static synchronized Supplier<Console> getConsoleFactory(ServerInfo server
2727
if (managers==null) {
2828
managers = new HashMap<>();
2929
}
30-
return managers.computeIfAbsent(server.label, label -> new Supplier<Console>() {
30+
return managers.computeIfAbsent(server.label(), label -> new Supplier<Console>() {
3131
ConsoleUtil consoleMgr = new ConsoleUtil(); //one console manager per language server type. This way each has their
3232
// own history (which limits number of open consoles per type)
3333
int consoleCounter = 0;
3434

3535
@Override
3636
public Console get() {
3737
if (isConsoleEnabled(server)) {
38-
return consoleMgr.getConsole(server.label+" Language Server "+consoleCounter());
38+
return consoleMgr.getConsole(server.label()+" Language Server "+consoleCounter());
3939
}
4040
return null;
4141
}
@@ -47,7 +47,7 @@ private synchronized int consoleCounter() {
4747
}
4848

4949
private static boolean isConsoleEnabled(ServerInfo server) {
50-
return LanguageServerCommonsActivator.getInstance().getPreferenceStore().getBoolean(server.preferenceKeyConsoleLog);
50+
return LanguageServerCommonsActivator.getInstance().getPreferenceStore().getBoolean(server.preferenceKeyConsoleLog());
5151
}
5252

5353
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2018, 2023 Pivotal, Inc.
2+
* Copyright (c) 2018, 2025 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -14,19 +14,20 @@ public class LanguageServerConsolePreferenceConstants {
1414

1515
public static final boolean ENABLE_BY_DEFAULT = false;
1616

17-
public static final String PREF_BOOT_JAVA_CONSOLE_ENABLED = "boot-java.console.enabled";
18-
public static final String PREF_BOOT_JAVA_LOG_FILE = "boot-java.log.file";
19-
public static final String PREF_CONCOURSE_CONSOLE_ENABLED = "concourse.console.enabled";
20-
public static final String PREF_CONCOURSE_FILE_LOG = "concourse.file.log";
21-
public static final String PREF_CLOUDFOUNDRY_CONSOLE_ENABLED = "cloudfoundry.console.enabled";
22-
public static final String PREF_CLOUDFOUNDRY_LOG_FILE = "cloudfoundry.log.file";
23-
public static final String PREF_BOSH_CONSOLE_ENABLED = "bosh.console.enabled";
24-
public static final String PREF_BOSH_LOG_FILE = "bosh.log.file";
17+
public static final String PREFIX_BOSH = "bosh";
18+
public static final String PREFIX_CF = "cloudfoundry";
19+
public static final String PREFIX_CONCOURSE = "concourse";
20+
public static final String PREFIX_SPRING_BOOT = "boot-java";
2521

26-
public static final ServerInfo SPRING_BOOT_SERVER = new ServerInfo(PREF_BOOT_JAVA_CONSOLE_ENABLED, PREF_BOOT_JAVA_LOG_FILE, "Spring Boot", "org.springframework.tooling.boot.ls");
27-
public static final ServerInfo CLOUDFOUNDRY_SERVER = new ServerInfo(PREF_CLOUDFOUNDRY_CONSOLE_ENABLED, PREF_CLOUDFOUNDRY_LOG_FILE, "Cloudfoundry", "org.springframework.tooling.cloudfoundry.manifest.ls");
28-
public static final ServerInfo CONCOURSE_SERVER = new ServerInfo(PREF_CONCOURSE_CONSOLE_ENABLED, PREF_CONCOURSE_FILE_LOG, "Concourse", "org.springframework.tooling.concourse.ls");
29-
public static final ServerInfo BOSH_SERVER = new ServerInfo(PREF_BOSH_CONSOLE_ENABLED, PREF_BOSH_LOG_FILE, "Bosh", "org.springframework.tooling.bosh.ls");
22+
public static final String SUFFIX_LOG_FILE = ".log.file";
23+
public static final String SUFFIX_LOG_CONSOLE = ".console.enabled";
24+
public static final String SUFFIX_LOG_LEVEL = ".log.level";
25+
26+
27+
public static final ServerInfo SPRING_BOOT_SERVER = new ServerInfo(PREFIX_SPRING_BOOT, "Spring Boot", "org.springframework.tooling.boot.ls");
28+
public static final ServerInfo CLOUDFOUNDRY_SERVER = new ServerInfo(PREFIX_CF, "Cloudfoundry", "org.springframework.tooling.cloudfoundry.manifest.ls");
29+
public static final ServerInfo CONCOURSE_SERVER = new ServerInfo(PREFIX_CONCOURSE, "Concourse", "org.springframework.tooling.concourse.ls");
30+
public static final ServerInfo BOSH_SERVER = new ServerInfo(PREFIX_BOSH, "Bosh", "org.springframework.tooling.bosh.ls");
3031

3132
public static final ServerInfo[] ALL_SERVERS = {
3233
SPRING_BOOT_SERVER,
@@ -35,20 +36,18 @@ public class LanguageServerConsolePreferenceConstants {
3536
BOSH_SERVER
3637
};
3738

38-
public static class ServerInfo {
39-
public final String preferenceKeyConsoleLog;
40-
public final String preferenceKeyFileLog;
41-
public final String label;
42-
public final String bundleId;
43-
public ServerInfo(String preferenceKeyConsoleLog, String preferenceKeyFileLog, String label, String bundleId) {
44-
this.preferenceKeyConsoleLog = preferenceKeyConsoleLog;
45-
this.preferenceKeyFileLog = preferenceKeyFileLog;
46-
this.label = label;
47-
this.bundleId = bundleId;
39+
public record ServerInfo(String lsPrefix, String label, String bundleId) {
40+
41+
public String preferenceKeyConsoleLog() {
42+
return lsPrefix + SUFFIX_LOG_CONSOLE;
4843
}
49-
@Override
50-
public String toString() {
51-
return "ServerInfo [preferenceKeyConsoleLog=" + preferenceKeyConsoleLog + ", label=" + label + ", bundleId=" + bundleId + "]";
44+
45+
public String preferenceKeyFileLog() {
46+
return lsPrefix + SUFFIX_LOG_FILE;
47+
}
48+
49+
public String preferenceKeyLogLevel() {
50+
return lsPrefix + SUFFIX_LOG_LEVEL;
5251
}
5352
}
5453
}

eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/preferences/LanguageServerPreferencesPage.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2018, 2023 Pivotal, Inc.
2+
* Copyright (c) 2018, 2025 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -15,6 +15,7 @@
1515
import java.nio.file.Path;
1616

1717
import org.eclipse.jface.preference.BooleanFieldEditor;
18+
import org.eclipse.jface.preference.ComboFieldEditor;
1819
import org.eclipse.jface.preference.FieldEditorPreferencePage;
1920
import org.eclipse.jface.preference.FileFieldEditor;
2021
import org.eclipse.jface.preference.IPreferenceStore;
@@ -55,18 +56,18 @@ protected void createFieldEditors() {
5556
fieldEditorParent.setLayout(layout);
5657
for (ServerInfo s : installedServers) {
5758
Group group = new Group(fieldEditorParent, SWT.None);
58-
group.setText(s.label);
59+
group.setText(s.label());
5960
group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
6061
layout = new GridLayout();
6162
layout.numColumns = 1;
6263
layout.marginWidth = 0;
6364
layout.marginHeight = 0;
6465
group.setLayout(layout);
6566

66-
Composite c1 = new Composite(group, SWT.NONE);
67-
c1.setLayout(new GridLayout());
68-
c1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
69-
addField(new FileFieldEditor(s.preferenceKeyFileLog, "Logging to File", true, c1) {
67+
Composite c = new Composite(group, SWT.NONE);
68+
c.setLayout(new GridLayout());
69+
c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
70+
addField(new FileFieldEditor(s.preferenceKeyFileLog(), "Logging to File", true, c) {
7071

7172
@Override
7273
protected boolean checkState() {
@@ -113,10 +114,22 @@ protected boolean checkState() {
113114

114115
});
115116

116-
Composite c2 = new Composite(group, SWT.NONE);
117-
c2.setLayout(new GridLayout());
118-
c2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
119-
addField(new BooleanFieldEditor(s.preferenceKeyConsoleLog, "Logging to Console", c2));
117+
c = new Composite(group, SWT.NONE);
118+
c.setLayout(new GridLayout());
119+
c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
120+
addField(new BooleanFieldEditor(s.preferenceKeyConsoleLog(), "Logging to Console", c));
121+
122+
c = new Composite(group, SWT.NONE);
123+
c.setLayout(new GridLayout());
124+
c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
125+
addField(new ComboFieldEditor(s.preferenceKeyLogLevel(), "Logging Level", new String[][] {
126+
{"Error", "error"},
127+
{"Warn", "warn"},
128+
{"Info", "info"},
129+
{"Debug", "debug"},
130+
{"Trace", "trace"},
131+
{"Off", "off"},
132+
}, c));
120133

121134
}
122135
}

eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/preferences/LsPreferencesUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class LsPreferencesUtil {
2626
public static ServerInfo[] getInstalledLs() {
2727
List<ServerInfo> serverInfos = new ArrayList<>();
2828
for (ServerInfo info : ALL_SERVERS) {
29-
Bundle bundle = Platform.getBundle(info.bundleId);
29+
Bundle bundle = Platform.getBundle(info.bundleId());
3030
if (bundle != null) {
3131
serverInfos.add(info);
3232
}
@@ -36,7 +36,7 @@ public static ServerInfo[] getInstalledLs() {
3636

3737
public static Optional<ServerInfo> getServerInfo(String bundleId) {
3838
for (ServerInfo info : ALL_SERVERS) {
39-
if (info.bundleId.equals(bundleId)) {
39+
if (info.bundleId().equals(bundleId)) {
4040
return Optional.of(info);
4141
}
4242
}

eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/preferences/PrefsInitializer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2018, 2023 Pivotal, Inc.
2+
* Copyright (c) 2018, 2025 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -22,7 +22,8 @@ public void initializeDefaultPreferences() {
2222
IPreferenceStore store = LanguageServerPreferencesPage.getPrefsStoreFromPlugin();
2323
ServerInfo[] installedServers = LsPreferencesUtil.getInstalledLs();
2424
for (ServerInfo s : installedServers) {
25-
store.setDefault(s.preferenceKeyConsoleLog, ENABLE_BY_DEFAULT);
25+
store.setDefault(s.preferenceKeyConsoleLog(), ENABLE_BY_DEFAULT);
26+
store.setDefault(s.preferenceKeyLogLevel(), "error");
2627
// Bundle bundle = Platform.getBundle(s.bundleId);
2728
// if (bundle != null) {
2829
// IPath stateLocation = Platform.getStateLocation(bundle);

vscode-extensions/commons-vscode/src/launch-util.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,13 @@ function prepareJvmArgs(options: ActivatorOptions, context: VSCode.ExtensionCont
225225
}
226226

227227
let logfile : string = options.workspaceOptions.get("logfile") || "/dev/null";
228+
const rootLogLevel = options.workspaceOptions.get("logLevel") || "error";
228229
//The logfile = '/dev/null' is handled specifically by the language server process so it works on all OSs.
229230
options.clientOptions.outputChannel.appendLine('Redirecting server logs to ' + logfile);
230231
const args = [
231232
'-Dsts.lsp.client=vscode',
232233
'-Dsts.log.file=' + logfile,
234+
`-Dlogging.level.root=${rootLogLevel}`,
233235
'-XX:TieredStopAtLevel=1'
234236
];
235237
if (port && port > 0) {

vscode-extensions/vscode-bosh/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@
9595
"description": "Additional 'user defined' VM args to pass to the language server process.",
9696
"scope": "machine-overridable"
9797
},
98+
"bosh.ls.logLevel": {
99+
"type": "string",
100+
"enum": [
101+
"error",
102+
"warn",
103+
"info",
104+
"debug",
105+
"trace",
106+
"off"
107+
],
108+
"default": "error",
109+
"description": "Log level for the Bosh Language Server"
110+
},
98111
"bosh.cli.command": {
99112
"type": [
100113
"string",

vscode-extensions/vscode-concourse/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@
6161
},
6262
"description": "Additional 'user defined' VM args to pass to the language server process.",
6363
"scope": "machine-overridable"
64+
},
65+
"concourse.ls.logLevel": {
66+
"type": "string",
67+
"enum": [
68+
"error",
69+
"warn",
70+
"info",
71+
"debug",
72+
"trace",
73+
"off"
74+
],
75+
"default": "error",
76+
"description": "Log level for the Concourse Language Server"
6477
}
6578
}
6679
},

vscode-extensions/vscode-manifest-yaml/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@
7878
},
7979
"description": "Additional 'user defined' VM args to pass to the language server process.",
8080
"scope": "machine-overridable"
81+
},
82+
"cloudfoundry-manifest.ls.logLevel": {
83+
"type": "string",
84+
"enum": [
85+
"error",
86+
"warn",
87+
"info",
88+
"debug",
89+
"trace",
90+
"off"
91+
],
92+
"default": "error",
93+
"description": "Log level for the Cloundfoundry Manifest Language Server"
8194
}
8295
}
8396
}

0 commit comments

Comments
 (0)