Skip to content

Commit

Permalink
services - using a java property instead of a String bean
Browse files Browse the repository at this point in the history
Taking into account comments from @juanluisrp
Can be used launching the jvm with `-Dgeonetwork.log.configdir=....`
  • Loading branch information
pmauduit committed Aug 19, 2021
1 parent a572112 commit b147ea5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
9 changes: 2 additions & 7 deletions services/src/main/java/org/fao/geonet/api/site/LogUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.fao.geonet.exceptions.OperationAbortedEx;
import org.fao.geonet.kernel.setting.Settings;
import org.fao.geonet.repository.SettingRepository;
import org.springframework.beans.BeansException;

import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -44,6 +43,7 @@
public class LogUtils {
public static final String DEFAULT_LOG_FILE = "log4j.xml";

public static final String GEONETWORK_LOG_CONFIGDIR_PROP = "geonetwork.log.configdir";

/**
* Refresh logger configuration. If settings is not set in database, using default log4j.xml
Expand All @@ -60,12 +60,7 @@ public static void refreshLogConfiguration() {
}


String loggingConfigurationPath;
try {
loggingConfigurationPath = (String) ApplicationContextHolder.get().getBean("loggingConfigurationPath");
} catch (BeansException e) {
loggingConfigurationPath = null;
}
String loggingConfigurationPath = System.getProperty(GEONETWORK_LOG_CONFIGDIR_PROP);
// get log config from db settings
String log4jProp = setting != null ? setting.getValue() : DEFAULT_LOG_FILE;
URL url ;
Expand Down
10 changes: 3 additions & 7 deletions services/src/main/java/org/fao/geonet/api/site/LoggingApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.commons.io.IOUtils;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.fao.geonet.ApplicationContextHolder;
import org.fao.geonet.api.site.model.ListLogFilesResponse;
import org.fao.geonet.constants.Geonet;
import org.fao.geonet.kernel.GeonetworkDataDirectory;
Expand Down Expand Up @@ -92,13 +91,10 @@ public List<ListLogFilesResponse.LogFileResponse> getLogFiles(
java.util.List<ListLogFilesResponse.LogFileResponse> logFileList =
new ArrayList<>();
String loggingConfigurationFolder = dataDirectory.getWebappDir() + "/WEB-INF/classes";
// overrides if a "loggingConfigurationPath" bean is available
try {
loggingConfigurationFolder = (String) ApplicationContextHolder.get().getBean("loggingConfigurationPath");
} catch (Exception e) {
// stick with the folder in the classpath.
// overrides if a "geonetwork.log.configdir" is available as a java property
if (System.getProperty(LogUtils.GEONETWORK_LOG_CONFIGDIR_PROP) != null) {
loggingConfigurationFolder = System.getProperty(LogUtils.GEONETWORK_LOG_CONFIGDIR_PROP);
}

File folder = new File(loggingConfigurationFolder);

if (folder != null && folder.isDirectory()) {
Expand Down

0 comments on commit b147ea5

Please sign in to comment.