From 565d734035564dca005d6c9b66bfb2e5c12d5374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20M=C3=BCller?= Date: Thu, 1 Aug 2019 10:09:03 +0200 Subject: [PATCH] MGR-65 support different location for appNG.log (#13) --- .../manager/business/LogConfig.java | 2 +- .../business/webservice/LogViewer.java | 25 ++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/appng/application/manager/business/LogConfig.java b/src/main/java/org/appng/application/manager/business/LogConfig.java index ab78f30..1dfcb27 100644 --- a/src/main/java/org/appng/application/manager/business/LogConfig.java +++ b/src/main/java/org/appng/application/manager/business/LogConfig.java @@ -47,7 +47,7 @@ @Scope("request") public class LogConfig extends ServiceAware implements DataProvider, ActionProvider { - static final String LOG4J_PROPS = "WEB-INF/conf/log4j.properties"; + public static final String LOG4J_PROPS = "WEB-INF/conf/log4j.properties"; @Value("${platform." + Platform.Property.PLATFORM_ROOT_PATH + "}") private String rootPath; diff --git a/src/main/java/org/appng/application/manager/business/webservice/LogViewer.java b/src/main/java/org/appng/application/manager/business/webservice/LogViewer.java index 9be6bf6..c9aa68a 100644 --- a/src/main/java/org/appng/application/manager/business/webservice/LogViewer.java +++ b/src/main/java/org/appng/application/manager/business/webservice/LogViewer.java @@ -16,8 +16,11 @@ package org.appng.application.manager.business.webservice; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.util.Iterator; +import java.util.Properties; import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; @@ -29,6 +32,8 @@ import org.appng.api.model.Application; import org.appng.api.model.Site; import org.appng.api.model.Subject; +import org.appng.application.manager.business.LogConfig; +import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; @@ -45,17 +50,25 @@ @Lazy @Component -@org.springframework.context.annotation.Scope("request") -public class LogViewer implements Webservice { +public class LogViewer implements Webservice, InitializingBean { - private static final String LOG_LOCATION = "WEB-INF/log/"; + private static final String WEBAPP_ROOT = "${webapp.root}"; + private static final String APPNG_APPENDER = "log4j.appender.appng.File"; protected static final String PERM_LOG_VIEWER = "platform.logfile"; @Value("${platform." + Platform.Property.PLATFORM_ROOT_PATH + "}") private String rootPath; - @Value("${platform." + Platform.Property.LOGFILE + "}") - private String logfile; + private String logFileLocation; + + public void afterPropertiesSet() throws Exception { + try (InputStream propsIs = new FileInputStream(new File(rootPath, LogConfig.LOG4J_PROPS))) { + Properties log4jProps = new Properties(); + log4jProps.load(propsIs); + logFileLocation = log4jProps.getProperty(APPNG_APPENDER); + logFileLocation = logFileLocation.replace(WEBAPP_ROOT, rootPath); + } + } public byte[] processRequest(Site site, Application application, Environment environment, Request request) throws BusinessException { @@ -96,7 +109,7 @@ public byte[] processRequest(Site site, Application application, Environment env } File getLogfile() { - return new File(rootPath, LOG_LOCATION + logfile); + return new File(logFileLocation); } public String getContentType() {