Second attempt to redirect log output to file
First attempt was flawed because some loggers can get instantiated before sysem property is set.
This commit is contained in:
@@ -11,6 +11,9 @@
|
||||
|
||||
package org.springframework.ide.vscode.commons.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -53,4 +56,15 @@ public class Log {
|
||||
logger.warn(msg, e);
|
||||
}
|
||||
|
||||
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"));
|
||||
}
|
||||
System.err.println("Redirecting log output to: "+logfile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user