Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-5289 load logs config in log service #2722

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -210,7 +201,9 @@ public static Map<String, Object> getServerConfigProps(Map<String, Object> confi
}

@SuppressWarnings("unchecked")
public static void patchConfigurationWithProperties(Map<String, Object> configProps, IVariableResolver varResolver) {
public static void patchConfigurationWithProperties(
Map<String, Object> configProps, IVariableResolver varResolver
) {
for (Map.Entry<String, Object> entry : configProps.entrySet()) {
Object propValue = entry.getValue();
if (propValue instanceof String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Loading