Skip to content

Commit

Permalink
MGR-65 support different location for appNG.log (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
madness-inc committed Aug 1, 2019
1 parent 25a8553 commit 565d734
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Expand Up @@ -47,7 +47,7 @@
@Scope("request")
public class LogConfig extends ServiceAware implements DataProvider, ActionProvider<LogFile> {

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;
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 565d734

Please sign in to comment.