diff --git a/main/launcher/pom.xml b/main/launcher/pom.xml index 25ff891e7..0a57682d6 100644 --- a/main/launcher/pom.xml +++ b/main/launcher/pom.xml @@ -42,16 +42,12 @@ - org.apache.logging.log4j - log4j-core + ch.qos.logback + logback-core - org.apache.logging.log4j - log4j-slf4j-impl - - - org.apache.logging.log4j - log4j-jul + ch.qos.logback + logback-classic \ No newline at end of file diff --git a/main/launcher/src/main/java/org/cryptomator/logging/ConfigurableFileAppender.java b/main/launcher/src/main/java/org/cryptomator/logging/ConfigurableFileAppender.java deleted file mode 100644 index a453b1adf..000000000 --- a/main/launcher/src/main/java/org/cryptomator/logging/ConfigurableFileAppender.java +++ /dev/null @@ -1,132 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Sebastian Stenzel and others. - * This file is licensed under the terms of the MIT license. - * See the LICENSE.txt file for more info. - * - * Contributors: - * Sebastian Stenzel - initial API and implementation - *******************************************************************************/ -package org.cryptomator.logging; - -import java.io.IOException; -import java.io.Serializable; -import java.net.URISyntaxException; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.regex.Pattern; - -import org.apache.commons.lang3.SystemUtils; -import org.apache.logging.log4j.core.Appender; -import org.apache.logging.log4j.core.Core; -import org.apache.logging.log4j.core.Filter; -import org.apache.logging.log4j.core.Layout; -import org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender; -import org.apache.logging.log4j.core.appender.FileManager; -import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute; -import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory; -import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required; -import org.apache.logging.log4j.util.Strings; - -/** - * A preconfigured FileAppender only relying on a configurable system property, e.g. -Dcryptomator.logPath=/var/log/cryptomator.log.
- * Other than the normal {@link org.apache.logging.log4j.core.appender.FileAppender} paths can be resolved relative to the users home directory. - */ -@Plugin(name = ConfigurableFileAppender.PLUGIN_NAME, category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE, printObject = true) -public class ConfigurableFileAppender extends AbstractOutputStreamAppender { - - static final String PLUGIN_NAME = "ConfigurableFile"; - private static final Pattern DRIVE_LETTER_WITH_PRECEEDING_SLASH = Pattern.compile("^/[A-Z]:", Pattern.CASE_INSENSITIVE); - - private ConfigurableFileAppender(String name, Layout layout, Filter filter, boolean ignoreExceptions, boolean immediateFlush, FileManager manager) { - super(name, layout, filter, ignoreExceptions, immediateFlush, manager); - LOGGER.info("Logging to " + manager.getFileName()); - } - - @PluginBuilderFactory - public static > B newBuilder() { - return new Builder().asBuilder(); - } - - /** - * Builds ConfigurableFileAppender instances. - * - * @param - * The type to build - */ - public static class Builder> extends AbstractOutputStreamAppender.Builder // - implements org.apache.logging.log4j.core.util.Builder { - - @Required(message = "No system property name containing the log file path provided.") - @PluginBuilderAttribute("pathPropertyName") - private String pathPropertyName; - - @PluginBuilderAttribute - private boolean append = true; - - @Override - public ConfigurableFileAppender build() { - final String pathProperty = System.getProperty(pathPropertyName); - if (Strings.isEmpty(pathProperty)) { - LOGGER.warn("No log file location provided in system property \"" + pathPropertyName + "\""); - return null; - } - - final Path filePath = parsePath(pathProperty); - if (filePath == null) { - LOGGER.warn("Invalid path \"" + pathProperty + "\""); - return null; - } - - if (!Files.exists(filePath.getParent())) { - try { - Files.createDirectories(filePath.getParent()); - } catch (IOException e) { - LOGGER.error("Could not create parent directories for log file located at " + filePath.toString(), e); - return null; - } - } - - FileManager manager = FileManager.getFileManager(filePath.toString(), append, false, isBufferedIo(), true, null, getOrCreateLayout(), getBufferSize(), getConfiguration()); - return new ConfigurableFileAppender(getName(), getLayout(), getFilter(), isIgnoreExceptions(), isImmediateFlush(), manager); - } - - public B withPathPropertyName(String pathPropertyName) { - this.pathPropertyName = pathPropertyName; - return asBuilder(); - } - - public B withAppend(boolean append) { - this.append = append; - return asBuilder(); - } - - } - - private static Path parsePath(String path) { - if (path.startsWith("~/")) { - // home-dir-relative Path: - final Path userHome = FileSystems.getDefault().getPath(SystemUtils.USER_HOME); - return userHome.resolve(path.substring(2)); - } else if (path.startsWith("/")) { - // absolute Path: - return FileSystems.getDefault().getPath(path); - } else { - // relative Path: - try { - String jarFileLocation = ConfigurableFileAppender.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath(); - if (SystemUtils.IS_OS_WINDOWS && DRIVE_LETTER_WITH_PRECEEDING_SLASH.matcher(jarFileLocation).find()) { - // on windows we need to remove a preceeding slash from "/C:/foo/bar": - jarFileLocation = jarFileLocation.substring(1); - } - final Path workingDir = FileSystems.getDefault().getPath(jarFileLocation).getParent(); - return workingDir.resolve(path); - } catch (URISyntaxException e) { - LOGGER.error("Unable to resolve working directory ", e); - return null; - } - } - } - -} diff --git a/main/launcher/src/main/java/org/cryptomator/logging/DebugMode.java b/main/launcher/src/main/java/org/cryptomator/logging/DebugMode.java index baa6c94f5..56179af08 100644 --- a/main/launcher/src/main/java/org/cryptomator/logging/DebugMode.java +++ b/main/launcher/src/main/java/org/cryptomator/logging/DebugMode.java @@ -6,29 +6,27 @@ package org.cryptomator.logging; import static java.util.Arrays.asList; -import static org.apache.logging.log4j.LogManager.ROOT_LOGGER_NAME; import java.util.Collection; import javax.inject.Inject; import javax.inject.Singleton; -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.core.LoggerContext; -import org.apache.logging.log4j.core.config.Configuration; -import org.apache.logging.log4j.core.config.LoggerConfig; import org.cryptomator.common.settings.Settings; -import org.slf4j.Logger; +import org.slf4j.ILoggerFactory; import org.slf4j.LoggerFactory; +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.LoggerContext; + @Singleton public class DebugMode { - private static final Logger LOG = LoggerFactory.getLogger(DebugMode.class); + private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(DebugMode.class); private static final Collection LOGGER_UPGRADES = asList( // - loggerUpgrade(ROOT_LOGGER_NAME, Level.INFO), // + loggerUpgrade(org.slf4j.Logger.ROOT_LOGGER_NAME, Level.INFO), // loggerUpgrade("org.cryptomator", Level.TRACE), // loggerUpgrade("org.eclipse.jetty.server.Server", Level.DEBUG) // ); @@ -48,10 +46,13 @@ public class DebugMode { } private void enable() { - LoggerContext context = (LoggerContext) LogManager.getContext(false); - Configuration config = context.getConfiguration(); - LOGGER_UPGRADES.forEach(loggerUpgrade -> loggerUpgrade.execute(config)); - context.updateLoggers(); + ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory(); + if (loggerFactory instanceof LoggerContext) { + LoggerContext context = (LoggerContext) loggerFactory; + LOGGER_UPGRADES.forEach(loggerUpgrade -> loggerUpgrade.execute(context)); + } else { + LOG.warn("SLF4J not bound to Logback."); + } } private static LoggerUpgrade loggerUpgrade(String loggerName, Level minLevel) { @@ -68,10 +69,10 @@ public class DebugMode { this.level = minLevel; } - public void execute(Configuration config) { - LoggerConfig loggerConfig = config.getLoggerConfig(loggerName); - if (loggerConfig.getLevel().isMoreSpecificThan(level)) { - loggerConfig.setLevel(level); + public void execute(LoggerContext context) { + Logger logger = context.getLogger(loggerName); + if (logger.getLevel().isGreaterOrEqual(level)) { + logger.setLevel(level); } } diff --git a/main/launcher/src/main/resources/log4j2.xml b/main/launcher/src/main/resources/log4j2.xml deleted file mode 100644 index 85afbab88..000000000 --- a/main/launcher/src/main/resources/log4j2.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/main/launcher/src/test/resources/log4j2.xml b/main/launcher/src/test/resources/log4j2.xml deleted file mode 100644 index e0ea8ca2b..000000000 --- a/main/launcher/src/test/resources/log4j2.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/main/launcher/src/test/resources/logback-test.xml b/main/launcher/src/test/resources/logback-test.xml new file mode 100644 index 000000000..6c38440e8 --- /dev/null +++ b/main/launcher/src/test/resources/logback-test.xml @@ -0,0 +1,18 @@ + + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + diff --git a/main/pom.xml b/main/pom.xml index ced9826b1..c8cc23d83 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -31,8 +31,8 @@ 1.2.2 0.6.0 1.0.2 - 2.8.1 1.7.25 + 1.2.2 4.12 4.12.1 1.3 @@ -119,19 +119,14 @@ ${slf4j.version} - org.apache.logging.log4j - log4j-core - ${log4j.version} + ch.qos.logback + logback-core + ${logback.version} - org.apache.logging.log4j - log4j-slf4j-impl - ${log4j.version} - - - org.apache.logging.log4j - log4j-jul - ${log4j.version} + ch.qos.logback + logback-classic + ${logback.version} diff --git a/main/uber-jar/pom.xml b/main/uber-jar/pom.xml index a16e82cb2..ef23b7fc6 100644 --- a/main/uber-jar/pom.xml +++ b/main/uber-jar/pom.xml @@ -41,17 +41,8 @@ ${project.version} - - - - - com.github.edwgiz - maven-shade-plugin.log4j2-cachefile-transformer - ${log4j.version} - - diff --git a/main/ui/src/main/java/org/cryptomator/ui/l10n/Localization.java b/main/ui/src/main/java/org/cryptomator/ui/l10n/Localization.java index e5876a5ef..b4e0d6a78 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/l10n/Localization.java +++ b/main/ui/src/main/java/org/cryptomator/ui/l10n/Localization.java @@ -46,21 +46,21 @@ public class Localization extends ResourceBundle { String language = Locale.getDefault().getLanguage(); String region = Locale.getDefault().getCountry(); - LOG.info("Detected language \"{}\" and region \"{}\"", language, region); + LOG.debug("Detected language \"{}\" and region \"{}\"", language, region); ResourceBundle localizationBundle = null; if (StringUtils.isNotEmpty(language) && StringUtils.isNotEmpty(region)) { String file = String.format(LOCALIZATION_FILENAME_FMT, language + "_" + region); - LOG.info("Attempting to load localization from: {}", file); + LOG.trace("Attempting to load localization from: {}", file); localizationBundle = loadLocalizationFile(file); } if (StringUtils.isNotEmpty(language) && localizationBundle == null) { String file = String.format(LOCALIZATION_FILENAME_FMT, language); - LOG.info("Attempting to load localization from: {}", file); + LOG.trace("Attempting to load localization from: {}", file); localizationBundle = loadLocalizationFile(file); } if (localizationBundle == null) { - LOG.info("No localization found. Falling back to default language."); + LOG.debug("No localization found. Falling back to default language."); localizationBundle = this.fallback; } this.localized = Objects.requireNonNull(localizationBundle);