From b9c491466f121f483a2a095ccea8e6b19d36b0af Mon Sep 17 00:00:00 2001 From: Kris De Volder Date: Mon, 22 Jul 2019 14:24:11 -0700 Subject: [PATCH] Do not auto-redirect language server logs to file See: https://github.com/spring-projects/sts4/issues/328 --- .../ide/vscode/commons/util/LogRedirect.java | 23 +++++++++---- .../vscode/commons/util/NullOutputStream.java | 34 +++++++++++++++++++ .../commons-vscode/src/launch-util.ts | 6 ++-- vscode-extensions/vscode-bosh/package.json | 7 ++++ .../vscode-concourse/package.json | 7 ++++ .../vscode-manifest-yaml/package.json | 7 ++++ .../vscode-spring-boot/package-lock.json | 4 +-- .../vscode-spring-boot/package.json | 11 ++++-- 8 files changed, 86 insertions(+), 13 deletions(-) create mode 100644 headless-services/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/NullOutputStream.java diff --git a/headless-services/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/LogRedirect.java b/headless-services/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/LogRedirect.java index e5fe0218b..fafd6fde7 100644 --- a/headless-services/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/LogRedirect.java +++ b/headless-services/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/LogRedirect.java @@ -11,6 +11,7 @@ package org.springframework.ide.vscode.commons.util; import java.io.File; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; @@ -20,20 +21,30 @@ public class LogRedirect { public static void bootRedirectToFile(String name) throws IOException { String logfilePath = System.getProperty("sts.log.file"); if (StringUtil.hasText(logfilePath)) { - File logfile = new File(logfilePath); - System.err.println("Redirecting log output to: "+logfile); - PrintStream logFile = new PrintStream(new FileOutputStream(logfile, false)); + PrintStream logFile = logFileStream(logfilePath); System.setErr(logFile); System.setOut(logFile); //Spring boot actually logs on sysout instead of syserr. } } + private static PrintStream logFileStream(String logfilePath) throws FileNotFoundException { + if (logfilePath.equals("/dev/null")) { + System.err.println("Disabling server log output. No more output will be sent after this."); + //redirect to a file called "/dev/null" works fine in Unix, but we also want this + // to work on Mac and Windows. So we create our own '/dev/null' stream + return new PrintStream(new NullOutputStream()); + } else { + System.err.println("Redirecting log output to: "+logfilePath); + File logfile = new File(logfilePath); + PrintStream logFile = new PrintStream(new FileOutputStream(logfile, false)); + return logFile; + } + } + public static void redirectToFile(String name) throws IOException { String logfilePath = System.getProperty("sts.log.file"); if (StringUtil.hasText(logfilePath)) { - File logfile = new File(logfilePath); - System.err.println("Redirecting log output to: "+logfile); - PrintStream logFile = new PrintStream(new FileOutputStream(logfile, false)); + PrintStream logFile = logFileStream(logfilePath); System.setErr(logFile); } } diff --git a/headless-services/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/NullOutputStream.java b/headless-services/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/NullOutputStream.java new file mode 100644 index 000000000..ea67ed92d --- /dev/null +++ b/headless-services/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/NullOutputStream.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2019 Pivotal, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.vscode.commons.util; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * An output stream that behaves just like "/dev/null" on Unix. I.e. any output + * written to it is silently discarded. + */ +public class NullOutputStream extends OutputStream { + + @Override + public void write(int b) throws IOException { + } + + @Override + public void write(byte[] b) throws IOException { + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + } + +} diff --git a/vscode-extensions/commons-vscode/src/launch-util.ts b/vscode-extensions/commons-vscode/src/launch-util.ts index d65fca77c..2b599982c 100644 --- a/vscode-extensions/commons-vscode/src/launch-util.ts +++ b/vscode-extensions/commons-vscode/src/launch-util.ts @@ -146,14 +146,14 @@ export function activate(options: ActivatorOptions, context: VSCode.ExtensionCon let processLaunchoptions = { cwd: VSCode.workspace.rootPath }; - let logfile = Path.join(tmpdir(), options.extensionId + '-' + Date.now()+'.log'); + let logfile : string = options.workspaceOptions.get("logfile") || "/dev/null"; + //The logfile = '/dev/null' is handled specifically by the language server process so it works on all OSs. log('Redirecting server logs to ' + logfile); const args = [ '-Dspring.lsp.client-port='+port, '-Dserver.port=' + port, '-Dsts.lsp.client=vscode', - '-Dsts.log.file=' + logfile, //old style log redirect - '-Dlogging.file=' + logfile, // spring boot log redirect + '-Dsts.log.file=' + logfile, '-XX:TieredStopAtLevel=1' ]; if (options.checkjvm) { diff --git a/vscode-extensions/vscode-bosh/package.json b/vscode-extensions/vscode-bosh/package.json index a38dd9a9b..f83d2c76f 100644 --- a/vscode-extensions/vscode-bosh/package.json +++ b/vscode-extensions/vscode-bosh/package.json @@ -64,6 +64,13 @@ "type": "object", "title": "Bosh CLI Configuration", "properties": { + "bosh.ls.logfile": { + "type": [ + "string", + "null" + ], + "description": "The path of a file to write language server logs. If not set or null, then logs are discarded." + }, "bosh.ls.java.heap": { "type": [ "string", diff --git a/vscode-extensions/vscode-concourse/package.json b/vscode-extensions/vscode-concourse/package.json index 6414d1218..3430b716f 100644 --- a/vscode-extensions/vscode-concourse/package.json +++ b/vscode-extensions/vscode-concourse/package.json @@ -32,6 +32,13 @@ "type": "object", "title": "Concourse Language Server Options", "properties": { + "concourse.ls.logfile": { + "type": [ + "string", + "null" + ], + "description": "The path of a file to write language server logs. If not set or null, then logs are discarded." + }, "concourse.ls.java.heap": { "type": [ "string", diff --git a/vscode-extensions/vscode-manifest-yaml/package.json b/vscode-extensions/vscode-manifest-yaml/package.json index eefa2d616..fdaaca35d 100644 --- a/vscode-extensions/vscode-manifest-yaml/package.json +++ b/vscode-extensions/vscode-manifest-yaml/package.json @@ -49,6 +49,13 @@ "configuration": { "title": "Cloudfoundry Manifest Language Server Configuration", "properties": { + "cloudfoundry-manifest.ls.logfile": { + "type": [ + "string", + "null" + ], + "description": "The path of a file to write language server logs. If not set or null, then logs are discarded." + }, "cloudfoundry-manifest.ls.java.heap": { "type": [ "string", diff --git a/vscode-extensions/vscode-spring-boot/package-lock.json b/vscode-extensions/vscode-spring-boot/package-lock.json index 0314899f1..197c08230 100644 --- a/vscode-extensions/vscode-spring-boot/package-lock.json +++ b/vscode-extensions/vscode-spring-boot/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscode-spring-boot", - "version": "1.8.0", + "version": "1.10.0", "lockfileVersion": 1, "requires": true, "dependencies": { "@pivotal-tools/commons-vscode": { "version": "file:../commons-vscode/pivotal-tools-commons-vscode-0.2.2.tgz", - "integrity": "sha512-wpuWx/wm1LYQ6vF2lfiLzETLzPFlNiUtzqoQd8eMhd5MQLeqJIAB9P2s3TggdD6bdpP+z2cknaAr5bpnTfMd2Q==", + "integrity": "sha512-i/QoMGh2yISKeZp0/8bEXON+z5sf6eNngHSXdS+DxpXksXNNyXn8gwg1byVdBl0x5nN16BKGqH+/obQH+Fj9Pg==", "requires": { "@pivotal-tools/jvm-launch-utils": "0.0.12", "deep-equal": "^1.0.1", diff --git a/vscode-extensions/vscode-spring-boot/package.json b/vscode-extensions/vscode-spring-boot/package.json index 33136cf79..c623a754a 100644 --- a/vscode-extensions/vscode-spring-boot/package.json +++ b/vscode-extensions/vscode-spring-boot/package.json @@ -133,10 +133,17 @@ }, "description": "Array of jmx urls pointing to remote spring boot applications to poll for live hover information. A typical url looks something like this: `service:jmx:rmi://localhost:9111/jndi/rmi://localhost:9111/jmxrmi`" }, + "spring-boot.ls.logfile": { + "type": [ + "string", + "null" + ], + "description": "The path of a file to write language server logs. If not set or null, then logs are discarded." + }, "spring-boot.ls.java.home": { "type": [ "string", - null + "null" ], "default": null, "description": "Override JAVA_HOME used for launching the spring-boot-language-server JVM process." @@ -144,7 +151,7 @@ "spring-boot.ls.java.heap": { "type": [ "string", - null + "null" ], "default": null, "description": "Max JVM heap value, passed via -Xmx argument when launching spring-boot-language-server JVM process."