diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/BaseWebApplication.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/BaseWebApplication.java index 14f962579c..87119703e6 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/BaseWebApplication.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/BaseWebApplication.java @@ -105,16 +105,7 @@ public boolean isMultiuser() { protected boolean loadServerConfiguration() throws DBException { Path configFilePath = getMainConfigurationFilePath().toAbsolutePath(); - Path configFolder = configFilePath.getParent(); - - // Configure logging - Path logbackConfigPath = getLogbackConfigPath(configFolder); - if (logbackConfigPath == null) { - System.err.println("Can't find slf4j configuration file in " + configFilePath.getParent()); - } else { - System.setProperty("logback.configurationFile", logbackConfigPath.toString()); - } Log.setLogHandler(new SLF4JLogHandler()); // Load config file @@ -210,7 +201,9 @@ public static Map getServerConfigProps(Map confi } @SuppressWarnings("unchecked") - public static void patchConfigurationWithProperties(Map configProps, IVariableResolver varResolver) { + public static void patchConfigurationWithProperties( + Map configProps, IVariableResolver varResolver + ) { for (Map.Entry entry : configProps.entrySet()) { Object propValue = entry.getValue(); if (propValue instanceof String) { diff --git a/server/bundles/io.cloudbeaver.slf4j/src/io/cloudbeaver/slf4j/CloudBeaverLogServiceProvider.java b/server/bundles/io.cloudbeaver.slf4j/src/io/cloudbeaver/slf4j/CloudBeaverLogServiceProvider.java index a46f62fff0..6800989ef2 100644 --- a/server/bundles/io.cloudbeaver.slf4j/src/io/cloudbeaver/slf4j/CloudBeaverLogServiceProvider.java +++ b/server/bundles/io.cloudbeaver.slf4j/src/io/cloudbeaver/slf4j/CloudBeaverLogServiceProvider.java @@ -17,8 +17,34 @@ package io.cloudbeaver.slf4j; import ch.qos.logback.classic.spi.LogbackServiceProvider; +import org.slf4j.helpers.Reporter; + +import java.nio.file.Files; +import java.nio.file.Path; public class CloudBeaverLogServiceProvider extends LogbackServiceProvider { + private static final String LOGBACK_CONF_FILE_PROPERTY = "logback.configurationFile"; + private static final String MAIN_LOGBACK_CONFIG = "conf/logback.xml"; + private static final String CUSTOM_LOGBACK_CONFIG = "conf/custom/logback.xml"; + + public CloudBeaverLogServiceProvider() { + if (System.getProperty(LOGBACK_CONF_FILE_PROPERTY) != null) { + return; + } + + String logbackConfig = null; + if (Files.exists(Path.of(CUSTOM_LOGBACK_CONFIG))) { + logbackConfig = CUSTOM_LOGBACK_CONFIG; + } else if (Files.exists(Path.of(MAIN_LOGBACK_CONFIG))) { + logbackConfig = MAIN_LOGBACK_CONFIG; + } + + if (logbackConfig != null) { + System.setProperty(LOGBACK_CONF_FILE_PROPERTY, Path.of(logbackConfig).toString()); + Reporter.info("Logback configuration is used: " + logbackConfig); + } else { + Reporter.info("No logback configuration found"); + } } }