X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fserver%2FLog4JLogIt.java;h=e295c867ff5d34ea164b1d113cb3cf96672f31df;hb=924b18d7469204ceaae60d7345712ea09f75a674;hp=0b91c9fc67971766253630866a747244a7e85dbf;hpb=33e7b1a9fa15b0b699d16e359b406195b7fe87be;p=aaf%2Fauthz.git diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/Log4JLogIt.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/Log4JLogIt.java index 0b91c9fc..e295c867 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/Log4JLogIt.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/Log4JLogIt.java @@ -20,6 +20,7 @@ */ package org.onap.aaf.auth.server; +import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; @@ -27,10 +28,13 @@ import org.apache.log4j.Logger; import org.onap.aaf.cadi.Access.Level; import org.onap.aaf.cadi.PropAccess; import org.onap.aaf.cadi.PropAccess.LogIt; +import org.onap.aaf.cadi.config.Config; import org.onap.aaf.misc.env.APIException; import org.onap.aaf.misc.env.log4j.LogFileNamer; public class Log4JLogIt implements LogIt { + protected static final String AAF_LOG4J_PREFIX = "aaf_log4j_prefix"; + // Sonar says cannot be static... it's ok. not too many PropAccesses created. private final SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); @@ -45,7 +49,19 @@ public class Log4JLogIt implements LogIt { private final Logger ltrace; - public Log4JLogIt(final String log_dir, final String log_level, final String propsFile, final String root) throws APIException { + public Log4JLogIt(final String[] args, final String root) throws APIException { + String propsFile = getArgOrVM(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props"; + String log_dir = getArgOrVM(Config.CADI_LOGDIR,args,"/opt/app/osaaf/logs"); + String etc_dir = getArgOrVM(Config.CADI_ETCDIR,args,"/opt/app/osaaf/etc"); + String log_level = getArgOrVM(Config.CADI_LOGLEVEL,args,"INFO"); + File logs = new File(log_dir); + if(!logs.isDirectory()) { + logs.delete(); + } + if(!logs.exists()) { + logs.mkdirs(); + } + LogFileNamer lfn = new LogFileNamer(log_dir,root); try { service=lfn.setAppender("service"); // when name is split, i.e. authz|service, the Appender is "authz", and "service" @@ -58,12 +74,29 @@ public class Log4JLogIt implements LogIt { linit = Logger.getLogger(init); ltrace = Logger.getLogger(trace); - lfn.configure(propsFile, log_level); + lfn.configure(etc_dir,propsFile, log_level); } catch (IOException e) { throw new APIException(e); } } + private static final String getArgOrVM(final String tag, final String args[], final String def) { + String tagEQ = tag + '='; + String value; + for(String arg : args) { + if(arg.startsWith(tagEQ)) { + return arg.substring(tagEQ.length()); + } + } + // check System.properties + value = System.getProperty(tag); + if(value!=null) { + return value; + } + + return def; + } + @Override public void push(Level level, Object... elements) { switch(level) {