diff --git a/main/commons/src/main/java/org/cryptomator/common/Environment.java b/main/commons/src/main/java/org/cryptomator/common/Environment.java index b45b743f2..033698f01 100644 --- a/main/commons/src/main/java/org/cryptomator/common/Environment.java +++ b/main/commons/src/main/java/org/cryptomator/common/Environment.java @@ -9,6 +9,7 @@ import javax.inject.Inject; import javax.inject.Singleton; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Optional; import java.util.Spliterator; import java.util.Spliterators; import java.util.function.Predicate; @@ -29,6 +30,7 @@ public class Environment { LOG.debug("cryptomator.settingsPath: {}", System.getProperty("cryptomator.settingsPath")); LOG.debug("cryptomator.ipcPortPath: {}", System.getProperty("cryptomator.ipcPortPath")); LOG.debug("cryptomator.keychainPath: {}", System.getProperty("cryptomator.keychainPath")); + LOG.debug("cryptomator.logDir: {}", System.getProperty("cryptomator.logDir")); } public Stream getSettingsPath() { @@ -43,6 +45,19 @@ public class Environment { return getPaths("cryptomator.keychainPath"); } + public Optional getLogDir() { + return getPath("cryptomator.logDir") // + .filter(Predicate.not(Path::isAbsolute)) // property must be a relative path + .map(ABSOLUTE_HOME_DIR::resolve); // resolve relative path against HOME + } + + + private Optional getPath(String propertyName) { + String value = System.getProperty(propertyName); + return Optional.ofNullable(value).map(Paths::get); + } + + // visible for testing Stream getPaths(String propertyName) { Stream rawSettingsPaths = getRawList(propertyName, PATH_LIST_SEP); diff --git a/main/commons/src/test/java/org/cryptomator/common/EnvironmentTest.java b/main/commons/src/test/java/org/cryptomator/common/EnvironmentTest.java index 8fe899630..12b8ba28e 100644 --- a/main/commons/src/test/java/org/cryptomator/common/EnvironmentTest.java +++ b/main/commons/src/test/java/org/cryptomator/common/EnvironmentTest.java @@ -2,6 +2,7 @@ package org.cryptomator.common; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -11,6 +12,7 @@ import org.junit.jupiter.api.Test; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @DisplayName("Environment Variables Test") @@ -60,6 +62,27 @@ class EnvironmentTest { MatcherAssert.assertThat(result, Matchers.contains(Paths.get("/home/testuser/AppData/Roaming/Cryptomator/keychain.json"))); } + @Test + @DisplayName("cryptomator.logDir=/foo/bar") + public void testAbsoluteLogDir() { + System.setProperty("cryptomator.logDir", "/foo/bar"); + + Optional logDir = env.getLogDir(); + + Assertions.assertFalse(logDir.isPresent()); + } + + @Test + @DisplayName("cryptomator.logDir=foo/bar") + public void testRelativeLogDir() { + System.setProperty("cryptomator.logDir", "foo/bar"); + + Optional logDir = env.getLogDir(); + + Assertions.assertTrue(logDir.isPresent()); + Assertions.assertEquals(Paths.get("/home/testuser/foo/bar"), logDir.get()); + } + @Nested @DisplayName("Path Lists") class SettingsPath { diff --git a/main/launcher/pom.xml b/main/launcher/pom.xml index aef980622..6677d1955 100644 --- a/main/launcher/pom.xml +++ b/main/launcher/pom.xml @@ -44,5 +44,9 @@ ch.qos.logback logback-classic + + org.codehaus.janino + janino + \ No newline at end of file diff --git a/main/launcher/src/main/resources/logback.xml b/main/launcher/src/main/resources/logback.xml new file mode 100644 index 000000000..46791f2dd --- /dev/null +++ b/main/launcher/src/main/resources/logback.xml @@ -0,0 +1,52 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + ${user.home}/Library/Logs/Cryptomator/cryptomator.log + + ${user.home}/${cryptomator.logDir}/cryptomator%i.log + 0 + 9 + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + ${user.home}/${cryptomator.logDir}/upgrade.log + true + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/launcher/src/test/resources/logback-test.xml b/main/launcher/src/test/resources/logback-test.xml index 043b6d20a..ebf1f5e7c 100644 --- a/main/launcher/src/test/resources/logback-test.xml +++ b/main/launcher/src/test/resources/logback-test.xml @@ -1,6 +1,4 @@ - - diff --git a/main/pom.xml b/main/pom.xml index add0f6161..5d98886e9 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -44,6 +44,7 @@ 1.7.25 1.2.3 + 3.0.12 5.4.0 2.24.0 @@ -161,6 +162,11 @@ logback-classic ${logback.version} + + org.codehaus.janino + janino + ${janino.version} +