Fix various Windows related issues

Fixes gh-1168
This commit is contained in:
Phillip Webb
2014-06-25 14:31:41 -07:00
parent 43cf95b845
commit 1f36d4657f
9 changed files with 53 additions and 12 deletions

View File

@@ -36,6 +36,7 @@ import org.springframework.util.ClassUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
/**
* An {@link ApplicationListener} that configures a logging framework depending on what it
@@ -147,6 +148,16 @@ public class LoggingApplicationListener implements SmartApplicationListener {
}
}
// Logback won't read backslashes so add a clean path for it to use
if (!StringUtils.hasLength(System.getProperty("LOG_TEMP"))) {
String path = System.getProperty("java.io.tmpdir");
path = StringUtils.cleanPath(path);
if(path.endsWith("/")) {
path = path.substring(0,path.length()-1);
}
System.setProperty("LOG_TEMP", path);
}
boolean environmentChanged = false;
for (Map.Entry<String, String> mapping : ENVIRONMENT_SYSTEM_PROPERTY_MAPPING
.entrySet()) {

View File

@@ -3,7 +3,7 @@
<include resource="org/springframework/boot/logging/logback/basic.xml"/>
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${java.io.tmpdir:-/tmp}/}spring.log}"/>
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
<property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${PID:- } [%t] --- %-40.40logger{39} : %m%n%wex"/>
<appender name="FILE"

View File

@@ -86,7 +86,12 @@ public class LoggingApplicationListenerTests {
}
private String tmpDir() {
return this.context.getEnvironment().resolvePlaceholders("${java.io.tmpdir}");
String path = this.context.getEnvironment().resolvePlaceholders("${java.io.tmpdir}");
path = path.replace("\\", "/");
if(path.endsWith("/")) {
path = path.substring(0, path.length()-1);
}
return path;
}
@Test

View File

@@ -61,7 +61,11 @@ public class LogbackLoggingSystemTests {
}
private String tmpDir() {
return System.getProperty("java.io.tmpdir");
String path = StringUtils.cleanPath(System.getProperty("java.io.tmpdir"));
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
return path;
}
@After

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${java.io.tmpdir:-/tmp}/}tmp.log}"/>
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}tmp.log}"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${LOG_FILE} [%t] ${PID:-????} %c{1}: %m%n</pattern>