Skip to content

Commit adb8b42

Browse files
V UdayaniV Udayani
authored andcommitted
change log levels for packages
1 parent eddb6eb commit adb8b42

File tree

17 files changed

+225
-70
lines changed

17 files changed

+225
-70
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package org.springframework.ide.vscode.commons.protocol;
2+
3+
public class LiveProcessLoggersSummary {
4+
5+
private String processType;
6+
private String processKey;
7+
private String processName;
8+
private String processID;
9+
private String packageName;
10+
private String effectiveLevel;
11+
private String configuredLevel;
12+
13+
14+
public String getProcessType() {
15+
return processType;
16+
}
17+
18+
public void setProcessType(String processType) {
19+
this.processType = processType;
20+
}
21+
22+
public String getProcessKey() {
23+
return processKey;
24+
}
25+
26+
public void setProcessKey(String processKey) {
27+
this.processKey = processKey;
28+
}
29+
30+
31+
public String getProcessName() {
32+
return processName;
33+
}
34+
35+
public void setProcessName(String processName) {
36+
this.processName = processName;
37+
}
38+
39+
public String getProcessID() {
40+
return processID;
41+
}
42+
43+
public void setProcessID(String processID) {
44+
this.processID = processID;
45+
}
46+
47+
public String getPackageName() {
48+
return packageName;
49+
}
50+
51+
public void setPackageName(String packageName) {
52+
this.packageName = packageName;
53+
}
54+
55+
public String getEffectiveLevel() {
56+
return effectiveLevel;
57+
}
58+
59+
public void setEffectiveLevel(String effectiveLevel) {
60+
this.effectiveLevel = effectiveLevel;
61+
}
62+
63+
public String getConfiguredLevel() {
64+
return configuredLevel;
65+
}
66+
67+
public void setConfiguredLevel(String configuredLevel) {
68+
this.configuredLevel = configuredLevel;
69+
}
70+
71+
72+
}

headless-services/commons/commons-lsp-extensions/src/main/java/org/springframework/ide/vscode/commons/protocol/STS4LanguageClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public interface STS4LanguageClient extends LanguageClient, SpringIndexLanguageC
5656
void liveProcessLoggersDataUpdated(LiveProcessSummary processKey);
5757

5858
@JsonNotification("sts/liveprocess/loglevel/updated")
59-
void liveProcessLogLevelUpdated(LiveProcessSummary processKey);
59+
void liveProcessLogLevelUpdated(LiveProcessLoggersSummary processKey);
6060

6161
@JsonNotification("sts/highlight")
6262
void highlight(HighlightParams highlights);

headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/LanguageServerHarness.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
115115
import org.springframework.ide.vscode.commons.protocol.CursorMovement;
116116
import org.springframework.ide.vscode.commons.protocol.HighlightParams;
117+
import org.springframework.ide.vscode.commons.protocol.LiveProcessLoggersSummary;
117118
import org.springframework.ide.vscode.commons.protocol.LiveProcessSummary;
118119
import org.springframework.ide.vscode.commons.protocol.STS4LanguageClient;
119120
import org.springframework.ide.vscode.commons.protocol.java.ClasspathListenerParams;
@@ -441,6 +442,10 @@ public void indexUpdated() {
441442
receiveIndexUpdated();
442443
}
443444

445+
@Override
446+
public void liveProcessLogLevelUpdated(LiveProcessLoggersSummary processKey) {
447+
}
448+
444449
});
445450

446451
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/ActuatorConnection.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ public interface ActuatorConnection {
3535
String getLiveMetrics(String metricName, String tags) throws IOException;
3636

3737
String getLoggers() throws IOException;
38+
39+
String configureLogLevel(Map<String, String> args) throws IOException;
3840
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/HttpActuatorConnection.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,15 @@ public String getLoggers() throws IOException {
8686
}
8787

8888
@Override
89-
public String changeLogLevel(Map<String, String> args) throws IOException {
89+
public String configureLogLevel(Map<String, String> args) throws IOException {
9090
UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromPath("/loggers/"+args.get("packageName"));
9191
if (args != null) {
9292
// for (Entry<String, String> e : args.entrySet()) {
9393
uriBuilder.queryParam("configuredLevel", args.get("configuredLevel"));
9494
// }
9595
}
96-
// /{ownerId}/new cases make REST Template URI template handler to think that {ownerId} is a URI parameter which it is not.
9796
String url = actuatorUrl + uriBuilder.toUriString();
98-
return restTemplate.getForObject(URI.create(url), String.class);
97+
return restTemplate.postForObject(URI.create(url), null, String.class);
9998
}
10099

101100
@Override

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/SpringProcessCommandHandler.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class SpringProcessCommandHandler {
4646
private static final String COMMAND_GET_REFRESH_METRICS = "sts/livedata/refresh/metrics";
4747
private static final String COMMAND_GET_LOGGERS = "sts/livedata/getLoggers";
4848
private static final String COMMAND_FETCH_LOGGERS_DATA = "sts/livedata/fetch/loggersData";
49-
private static final String COMMAND_CHANGE_LOGLEVEL = "sts/livedata/change/logLevel";
49+
private static final String COMMAND_CONFIGURE_LOGLEVEL = "sts/livedata/configure/logLevel";
5050

5151
private final SpringProcessConnectorService connectorService;
5252
private final SpringProcessConnectorLocal localProcessConnector;
@@ -103,10 +103,10 @@ public SpringProcessCommandHandler(SimpleLanguageServer server, SpringProcessCon
103103
});
104104
log.info("Registered command handler: {}",COMMAND_FETCH_LOGGERS_DATA);
105105

106-
server.onCommand(COMMAND_CHANGE_LOGLEVEL, (params) -> {
107-
return changeLogLevel(params);
106+
server.onCommand(COMMAND_CONFIGURE_LOGLEVEL, (params) -> {
107+
return configureLogLevel(params);
108108
});
109-
log.info("Registered command handler: {}",COMMAND_CHANGE_LOGLEVEL);
109+
log.info("Registered command handler: {}",COMMAND_CONFIGURE_LOGLEVEL);
110110

111111
server.onCommand(COMMAND_LIST_CONNECTED, (params) -> {
112112
List<LiveProcessSummary> result = new ArrayList<>();
@@ -361,17 +361,18 @@ private CompletableFuture<Object> handleFetchLoggersDataRequest(ExecuteCommandPa
361361
return CompletableFuture.completedFuture(null);
362362
}
363363

364-
private CompletableFuture<Object> changeLogLevel(ExecuteCommandParams params) {
364+
private CompletableFuture<Object> configureLogLevel(ExecuteCommandParams params) {
365365
Map<String, String> args = new HashMap<>();
366366
args.put("packageName", getArgumentByKey(params, "packageName"));
367367
args.put("configuredLevel", getArgumentByKey(params, "configuredLevel"));
368+
args.put("effectiveLevel", getArgumentByKey(params, "effectiveLevel"));
368369
SpringProcessParams springProcessParams = new SpringProcessParams();
369370
springProcessParams.setProcessKey(getProcessKey(params));
370-
springProcessParams.setEndpoint("loggers");
371+
springProcessParams.setEndpoint(getArgumentByKey(params, "endpoint"));
371372
springProcessParams.setArgs(args);
372373

373374
if (springProcessParams.getProcessKey() != null) {
374-
connectorService.changeLogLevel(springProcessParams);
375+
connectorService.configureLogLevel(springProcessParams);
375376
}
376377

377378
return CompletableFuture.completedFuture(null);

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/SpringProcessConnector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ public interface SpringProcessConnector {
3232
SpringProcessGcPausesMetricsLiveData refreshGcPausesMetrics(SpringProcessLiveData current, String metricName, String tags) throws Exception;
3333
SpringProcessMemoryMetricsLiveData refreshMemoryMetrics(SpringProcessLiveData current, String metricName, String tags) throws Exception;
3434
SpringProcessLoggersData getLoggers(SpringProcessLiveData currentData) throws Exception;
35-
void changeLogLevel(SpringProcessLiveData currentData, Map<String, String> args) throws Exception;
35+
SpringProcessUpdatedLogLevelData configureLogLevel(SpringProcessLiveData currentData, Map<String, String> args) throws Exception;
3636
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/SpringProcessConnectorOverHttp.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,22 @@ public SpringProcessLoggersData getLoggers(SpringProcessLiveData currentData)
185185

186186

187187
@Override
188-
public void changeLogLevel(SpringProcessLiveData currentData, Map<String, String> args) throws Exception {
188+
public SpringProcessUpdatedLogLevelData configureLogLevel(SpringProcessLiveData currentData, Map<String, String> args) throws Exception {
189189
if (actuatorConnection != null) {
190-
SpringProcessLoggersData loggersData = new SpringProcessLiveDataExtractorOverHttp().changeLogLevel(getProcessType(), actuatorConnection, processID, processName, currentData, args);
190+
SpringProcessUpdatedLogLevelData springProcessUpdatedLoggersData = new SpringProcessLiveDataExtractorOverHttp().configureLogLevel(getProcessType(), actuatorConnection, processID, processName, currentData, args);
191191

192192
if (this.processID == null) {
193-
this.processID = loggersData.getProcessID();
193+
this.processID = springProcessUpdatedLoggersData.getProcessID();
194194
}
195195

196196
if (this.processName == null) {
197-
this.processName = loggersData.getProcessName();
197+
this.processName = springProcessUpdatedLoggersData.getProcessName();
198+
return springProcessUpdatedLoggersData;
198199
}
199200

200201
}
201202

202-
throw new Exception("no loggers data received, lets try again");
203+
throw new Exception("configure log levels failed, lets try again");
203204
}
204205

205206

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/SpringProcessConnectorOverJMX.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,26 +235,27 @@ public SpringProcessLoggersData getLoggers(SpringProcessLiveData currentData) th
235235
}
236236

237237
@Override
238-
public void changeLogLevel(SpringProcessLiveData currentData, Map<String, String> args) throws Exception {
238+
public SpringProcessUpdatedLogLevelData configureLogLevel(SpringProcessLiveData currentData, Map<String, String> args) throws Exception {
239239
log.info("try to open JMX connection to: " + jmxURL);
240240

241241
if (jmxConnection != null) {
242242
try {
243243
SpringProcessLiveDataExtractorOverJMX springJMXConnector = new SpringProcessLiveDataExtractorOverJMX();
244244

245245
log.info("retrieve live data from: " + jmxURL);
246-
springJMXConnector.changeLogLevel(getProcessType(), jmxConnection, processID, processName, currentData, args);
246+
SpringProcessUpdatedLogLevelData springProcessUpdatedLoggersData = springJMXConnector.configureLogLevel(getProcessType(), jmxConnection, processID, processName, currentData, args);
247247

248248
// if (loggersData != null) {
249249
// return loggersData;
250250
// }
251+
return springProcessUpdatedLoggersData;
251252
}
252253
catch (Exception e) {
253254
log.error("exception while connecting to jmx: " + jmxURL, e);
254255
}
255256
}
256257

257-
throw new Exception("no loggers data received, lets try again");
258+
throw new Exception("configure log level failed, lets try again");
258259
}
259260

260261
@Override

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/SpringProcessConnectorService.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -362,36 +362,36 @@ public void getLoggersData(IndefiniteProgressTask progressTask, SpringProcessPar
362362

363363
}
364364

365-
public void changeLogLevel(SpringProcessParams springProcessParams) {
365+
public void configureLogLevel(SpringProcessParams springProcessParams) {
366366
log.info("change log level: " + springProcessParams.getProcessKey());
367367

368368
SpringProcessConnector connector = this.connectors.get(springProcessParams.getProcessKey());
369369
if (connector != null) {
370370
final IndefiniteProgressTask progressTask = getProgressTask(
371-
"spring-process-connector-service-change-log-level" + springProcessParams.getProcessKey(), "Loggers", null);
371+
"spring-process-connector-service-configure-log-level" + springProcessParams.getProcessKey(), "Loggers", null);
372372
System.out.println(progressTask);
373-
changeLogLevel(progressTask, springProcessParams, connector, 0, TimeUnit.SECONDS, 0);
373+
configureLogLevel(progressTask, springProcessParams, connector, 0, TimeUnit.SECONDS, 0);
374374
}
375375
}
376376

377-
private void changeLogLevel(IndefiniteProgressTask progressTask, SpringProcessParams springProcessParams,
377+
private void configureLogLevel(IndefiniteProgressTask progressTask, SpringProcessParams springProcessParams,
378378
SpringProcessConnector connector, long delay, TimeUnit unit, int retryNo) {
379379
String processKey = springProcessParams.getProcessKey();
380380
String endpoint = springProcessParams.getEndpoint();
381381

382-
String progressMessage = "change log level for Spring process: " + processKey + " - retry no: " + retryNo;
382+
String progressMessage = "configure log level for Spring process: " + processKey + " - retry no: " + retryNo;
383383
log.info(progressMessage);
384384

385385
this.scheduler.schedule(() -> {
386386

387387
try {
388388
progressTask.progressEvent(progressMessage);
389389
if(LOGGERS.equals(endpoint)) {
390-
connector.changeLogLevel(this.liveDataProvider.getCurrent(processKey), springProcessParams.getArgs());
390+
SpringProcessUpdatedLogLevelData springProcessUpdatedLoggersData = connector.configureLogLevel(this.liveDataProvider.getCurrent(processKey), springProcessParams.getArgs());
391391

392392
// if (loggersData != null) {
393393
// if (!this.liveDataProvider.addLoggers(processKey, loggersData)) {
394-
this.liveDataProvider.updateLoggers(processKey, null);
394+
this.liveDataProvider.updateLogLevel(processKey, springProcessUpdatedLoggersData);
395395
// }
396396

397397
this.connectedSuccess.put(processKey, true);
@@ -405,7 +405,7 @@ private void changeLogLevel(IndefiniteProgressTask progressTask, SpringProcessPa
405405
log.info("problem occured during process live data refresh", e);
406406

407407
if (retryNo < maxRetryCount && isKnownProcessKey(processKey)) {
408-
getLoggersData(progressTask, springProcessParams, connector, retryDelayInSeconds, TimeUnit.SECONDS,
408+
configureLogLevel(progressTask, springProcessParams, connector, retryDelayInSeconds, TimeUnit.SECONDS,
409409
retryNo + 1);
410410
}
411411
else {

0 commit comments

Comments
 (0)