*/
package org.onap.aaf.auth.server;
+import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
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");
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"
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) {