From 67e5131718aa91ce994eaf8a003b27628d89bcd1 Mon Sep 17 00:00:00 2001 From: Kris De Volder Date: Wed, 31 Jan 2018 14:47:40 -0800 Subject: [PATCH] More robust log file redirection. I.e. directly redirect System.err stream to a file. Instead of trying to get a hodge-podge of different java logging systems to all send output to the same file. --- .../ide/vscode/commons/util/LogRedirect.java | 14 +++++++------- .../commons-vscode/src/launch-util.ts | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) 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 46aecf74c..1200c15cc 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,19 +11,19 @@ package org.springframework.ide.vscode.commons.util; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.PrintStream; public class LogRedirect { public static void redirectToFile(String name) throws IOException { - File logfile = null; - if (System.getProperty("org.slf4j.simpleLogger.logFile") == null) { - logfile = File.createTempFile(name, ".log"); - System.setProperty("org.slf4j.simpleLogger.logFile", logfile.toString()); - } else { - logfile = new File(System.getProperty("org.slf4j.simpleLogger.logFile")); + String logfilePath = System.getProperty("sts.log.file"); + if (StringUtil.hasText(logfilePath)) { + File logfile = new File(logfilePath); + System.err.println("Redirecting log output to: "+logfile); + System.setErr(new PrintStream(new FileOutputStream(logfile, false))); } - System.err.println("Redirecting log output to: "+logfile); } } diff --git a/vscode-extensions/commons-vscode/src/launch-util.ts b/vscode-extensions/commons-vscode/src/launch-util.ts index ef7bde2bc..9011067ab 100644 --- a/vscode-extensions/commons-vscode/src/launch-util.ts +++ b/vscode-extensions/commons-vscode/src/launch-util.ts @@ -109,7 +109,7 @@ export function activate(options: ActivatorOptions, context: VSCode.ExtensionCon const args = [ '-Dserver.port=' + port, '-Dsts.lsp.client=vscode', - '-Dorg.slf4j.simpleLogger.logFile=' + logfile + '-Dsts.log.file=' + logfile ]; if (options.classpath) { const classpath = options.classpath(context, version);