Create method of Logging to O/S from Container

Issue-ID: AAF-211
Change-Id: Ib5c369c24082823f6f8cfde7609b966f57085665
Signed-off-by: Instrumental <jcgmisc@stl.gathman.org>
diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/Batch.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/Batch.java
index 64c0971..d4b582a 100644
--- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/Batch.java
+++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/Batch.java
@@ -422,12 +422,7 @@
 			// Flow all Env Logs to Log4j, with ENV
 
 			LogFileNamer lfn;
-			if ((batchEnv = env.getProperty(CASS_ENV)) == null) {
-				lfn = new LogFileNamer(logDir()).noPID();
-			} else {
-				lfn = new LogFileNamer(logDir()).noPID();
-			}
-
+			lfn = new LogFileNamer(logDir(),"").noPID();
 			lfn.setAppender("authz-batch");
 			lfn.setAppender("aspr|ASPR");
 			lfn.setAppender("sync");
diff --git a/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/AAF_CM.java b/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/AAF_CM.java
index c1bc820..aee4887 100644
--- a/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/AAF_CM.java
+++ b/auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/AAF_CM.java
@@ -22,6 +22,7 @@
 
 package org.onap.aaf.auth.cm;
 
+import java.io.File;
 import java.lang.reflect.Constructor;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -49,6 +50,7 @@
 import org.onap.aaf.auth.rserv.HttpMethods;
 import org.onap.aaf.auth.server.AbsService;
 import org.onap.aaf.auth.server.JettyServiceStarter;
+import org.onap.aaf.auth.server.Log4JLogIt;
 import org.onap.aaf.cadi.Access;
 import org.onap.aaf.cadi.CadiException;
 import org.onap.aaf.cadi.LocatorException;
@@ -226,10 +228,21 @@
 	}
 
 	public static void main(final String[] args) {
-		PropAccess propAccess = new PropAccess(args);
 		try {
+			String propsFile = getArg(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props";
+			String log_dir = getArg(Config.CADI_LOGDIR,args,"./logs");
+			String log_level = getArg(Config.CADI_LOGLEVEL,args,"INFO");
+			File logs = new File(log_dir);
+			if(!logs.isDirectory()) {
+				logs.delete();
+			}
+			if(!logs.exists()) {
+				logs.mkdirs();
+			}
+			Log4JLogIt logIt = new Log4JLogIt(log_dir,log_level,propsFile, "cm");
+			PropAccess propAccess = new PropAccess(logIt,args);
+ 		
  			AAF_CM service = new AAF_CM(new AuthzEnv(propAccess));
-//			env.setLog4JNames("log4j.properties","authz","cm","audit","init","trace");
 			JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
 			jss.start();
 		} catch (Exception e) {
diff --git a/auth/auth-core/pom.xml b/auth/auth-core/pom.xml
index d0d2fb6..a7f60ae 100644
--- a/auth/auth-core/pom.xml
+++ b/auth/auth-core/pom.xml
@@ -119,7 +119,10 @@
 			<scope>compile</scope>
 		</dependency>
 
-
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-log4j12</artifactId>
+		</dependency>
 	</dependencies>
 	
 	<build>
diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzEnv.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzEnv.java
index 300e408..a396cd9 100644
--- a/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzEnv.java
+++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/env/AuthzEnv.java
@@ -29,14 +29,11 @@
 import org.onap.aaf.cadi.Access;
 import org.onap.aaf.cadi.CadiException;
 import org.onap.aaf.cadi.PropAccess;
-import org.onap.aaf.cadi.PropAccess.LogIt;
 import org.onap.aaf.cadi.Symm;
 import org.onap.aaf.cadi.config.Config;
-import org.onap.aaf.misc.env.APIException;
 import org.onap.aaf.misc.env.Decryptor;
 import org.onap.aaf.misc.env.Encryptor;
-import org.onap.aaf.misc.env.impl.Log4JLogTarget;
-import org.onap.aaf.misc.env.log4j.LogFileNamer;
+import org.onap.aaf.misc.env.LogTarget;
 import org.onap.aaf.misc.rosetta.env.RosettaEnv;
 
 
@@ -79,39 +76,46 @@
 		access = pa;
 		times = new long[20];
 		idx = 0;
+		fatal = new AccessLogTarget(access, Level.ERROR);
+		error = fatal;
+		audit = new AccessLogTarget(access, Level.AUDIT);
+		init = new AccessLogTarget(access, Level.INIT);
+		warn = new AccessLogTarget(access, Level.WARN);
+		info = new AccessLogTarget(access, Level.INFO);
+		debug = new AccessLogTarget(access, Level.DEBUG);
+		trace = new AccessLogTarget(access, Level.TRACE);
 	}
 	
-	private class Log4JLogit implements LogIt {
+	private class AccessLogTarget implements LogTarget {
+		private final Level level;
+		private final Access access;
+		
+		public AccessLogTarget(final Access access, final Level level) {
+			this.level = level;
+			this.access = access;
+		}
 		
 		@Override
-		public void push(Level level, Object... elements) {
-			switch(level) {
-				case AUDIT:
-					audit.log(elements);
-					break;
-				case DEBUG:
-					debug.log(elements);
-					break;
-				case ERROR:
-					error.log(elements);
-					break;
-				case INFO:
-					info.log(elements);
-					break;
-				case INIT:
-					init.log(elements);
-					break;
-				case NONE:
-					break;
-				case WARN:
-					warn.log(elements);
-					break;
-			}
-			
+		public void log(Object... msgs) {
+			access.log(level, msgs);
+		}
+
+		@Override
+		public void log(Throwable e, Object... msgs) {
+			access.log(Level.ERROR, msgs);
+		}
+
+		@Override
+		public boolean isLoggable() {
+			return access.willLog(level);
+		}
+
+		@Override
+		public void printf(String fmt, Object... vars) {
+			access.printf(level, fmt, vars);
 		}
 		
 	}
-
 	@Override
 	public AuthzTransImpl newTrans() {
 		synchronized(this) {
@@ -192,29 +196,6 @@
 	public void setLogLevel(Level level) {
 		access.setLogLevel(level);
 	}
-
-	public void setLog4JNames(String path, String root, String _service, String _audit, String _init, String _trace) throws APIException {
-		LogFileNamer lfn = new LogFileNamer(root);
-		if(_service==null) {
-			throw new APIException("AuthzEnv.setLog4JNames \"_service\" required (as default).  Others can be null");
-		}
-		String service=_service=lfn.setAppender(_service); // when name is split, i.e. authz|service, the Appender is "authz", and "service"
-		String audit=_audit==null?service:lfn.setAppender(_audit);     // is part of the log-file name
-		String init=_init==null?service:lfn.setAppender(_init);
-		String trace=_trace==null?service:lfn.setAppender(_trace);
-		//TODO Validate path on Classpath
-		lfn.configure(path);
-		super.fatal = new Log4JLogTarget(service,org.apache.log4j.Level.FATAL);
-		super.error = new Log4JLogTarget(service,org.apache.log4j.Level.ERROR);
-		super.warn = new Log4JLogTarget(service,org.apache.log4j.Level.WARN);
-		super.audit = new Log4JLogTarget(audit,org.apache.log4j.Level.WARN);
-		super.init = new Log4JLogTarget(init,org.apache.log4j.Level.WARN);
-		super.info = new Log4JLogTarget(service,org.apache.log4j.Level.INFO);
-		super.debug = new Log4JLogTarget(service,org.apache.log4j.Level.DEBUG);
-		super.trace = new Log4JLogTarget(trace,org.apache.log4j.Level.TRACE);
-		
-		access.set(new Log4JLogit());
-	}
 	
 	private static final byte[] ENC="enc:".getBytes();
 	public String decrypt(String encrypted, final boolean anytext) throws IOException {
diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsService.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsService.java
index e1c0171..12b19d2 100644
--- a/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsService.java
+++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/AbsService.java
@@ -46,6 +46,7 @@
 import org.onap.aaf.misc.env.impl.BasicEnv;
 
 public abstract class AbsService<ENV extends BasicEnv, TRANS extends Trans> extends RServlet<TRANS> {
+	protected static final String AAF_LOG4J_PREFIX = "aaf_log4j_prefix";
 	public final Access access;
 	public final ENV env;
 	private AAFConHttp aafCon;
@@ -153,4 +154,15 @@
 	public<RET> RET clientAsUser(TaggedPrincipal p,Retryable<RET> retryable) throws APIException, LocatorException, CadiException  {
 			return aafCon.hman().best(new HTransferSS(p,app_name, aafCon.securityInfo()), retryable);
 	}
+	
+	protected static final String getArg(final String tag, final String args[], final String def) {
+		String value = def;
+		String tagEQ = tag + '=';
+		for(String arg : args) {
+			if(arg.startsWith(tagEQ)) {
+				value = arg.substring(tagEQ.length());
+			}
+		}
+		return value;
+	}
 }
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
new file mode 100644
index 0000000..0b91c9f
--- /dev/null
+++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/server/Log4JLogIt.java
@@ -0,0 +1,100 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+package org.onap.aaf.auth.server;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+
+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.misc.env.APIException;
+import org.onap.aaf.misc.env.log4j.LogFileNamer;
+
+public class Log4JLogIt implements LogIt {
+	// 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 String service;
+	private final String audit;
+	private final String init;
+	private final String trace;
+
+	private final Logger lservice;
+	private final Logger laudit;
+	private final Logger linit;
+	private final Logger ltrace;
+
+
+	public Log4JLogIt(final String log_dir, final String log_level, final String propsFile, final String root) throws APIException {
+		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"
+			audit=lfn.setAppender("audit");     // is part of the log-file name
+			init=lfn.setAppender("init");
+			trace=lfn.setAppender("trace");
+
+			lservice = Logger.getLogger(service);
+			laudit = Logger.getLogger(audit);
+			linit = Logger.getLogger(init);
+			ltrace = Logger.getLogger(trace);
+	
+			lfn.configure(propsFile, log_level);
+		} catch (IOException e) {
+			throw new APIException(e);
+		}
+	}
+	
+	@Override
+	public void push(Level level, Object... elements) {
+		switch(level) {
+			case AUDIT:
+				laudit.warn(PropAccess.buildMsg(audit, iso8601, level, elements));
+				break;
+			case INIT:
+				linit.warn(PropAccess.buildMsg(init, iso8601, level, elements));
+				break;
+			case ERROR:
+				lservice.error(PropAccess.buildMsg(service, iso8601, level, elements));
+				break;
+			case WARN:
+				lservice.warn(PropAccess.buildMsg(service, iso8601, level, elements));
+				break;
+			case INFO:
+				lservice.info(PropAccess.buildMsg(service, iso8601, level, elements));
+				break;
+			case DEBUG:
+				lservice.debug(PropAccess.buildMsg(service, iso8601, level, elements));
+				break;
+			case TRACE:
+				ltrace.trace(PropAccess.buildMsg(service, iso8601, level, elements));
+				break;
+			case NONE:
+				break;
+			default:
+				lservice.info(PropAccess.buildMsg(service, iso8601, level, elements));
+				break;
+		
+		}
+
+	}
+}
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java
index 4d088c5..6413b09 100644
--- a/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java
+++ b/auth/auth-core/src/test/java/org/onap/aaf/auth/env/test/JU_AuthzEnv.java
@@ -21,22 +21,20 @@
  ******************************************************************************/
 package org.onap.aaf.auth.env.test;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.mockito.Mockito.mock;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Properties;
-import org.onap.aaf.cadi.Access;
-import static org.mockito.Mockito.when;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.Mock;
 import org.onap.aaf.auth.env.AuthzEnv;
+import org.onap.aaf.cadi.Access;
 import org.onap.aaf.cadi.PropAccess;
-import org.onap.aaf.cadi.Access.Level;
-import org.onap.aaf.cadi.config.Config;
-import org.onap.aaf.misc.env.APIException;
 import org.powermock.modules.junit4.PowerMockRunner;
 
 import junit.framework.Assert;
@@ -85,12 +83,6 @@
 		Assert.assertNotNull(authzEnv.getProperties("test"));
 	}
 
-	@Test(expected = APIException.class)
-	public void checkSetLog4JNames() throws APIException {//TODO: Find better way to test instead of just seeing if strings pass
-		authzEnv.setLog4JNames("path", "root","service","audit","init","trace");
-		authzEnv.setLog4JNames("path", "root",null,"audit","init","trace");
-	}
-
 	@Test
 	public void checkPropertyGetters(){
 		authzEnv.setProperty("key","value");
diff --git a/auth/auth-fs/src/main/java/org/onap/aaf/auth/fs/AAF_FS.java b/auth/auth-fs/src/main/java/org/onap/aaf/auth/fs/AAF_FS.java
index 5079139..719daaa 100644
--- a/auth/auth-fs/src/main/java/org/onap/aaf/auth/fs/AAF_FS.java
+++ b/auth/auth-fs/src/main/java/org/onap/aaf/auth/fs/AAF_FS.java
@@ -23,6 +23,7 @@
 
 import static org.onap.aaf.auth.rserv.HttpMethods.GET;
 
+import java.io.File;
 import java.io.IOException;
 
 import javax.servlet.Filter;
@@ -36,6 +37,7 @@
 import org.onap.aaf.auth.rserv.HttpCode;
 import org.onap.aaf.auth.server.AbsService;
 import org.onap.aaf.auth.server.JettyServiceStarter;
+import org.onap.aaf.auth.server.Log4JLogIt;
 import org.onap.aaf.cadi.Access.Level;
 import org.onap.aaf.cadi.CadiException;
 import org.onap.aaf.cadi.LocatorException;
@@ -102,10 +104,21 @@
 	}
 	
 	public static void main(final String[] args) {
-		PropAccess propAccess = new PropAccess(args);
 		try {
+			String propsFile = getArg(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props";
+			String log_dir = getArg(Config.CADI_LOGDIR,args,"./logs");
+			String log_level = getArg(Config.CADI_LOGLEVEL,args,"INFO");
+			File logs = new File(log_dir);
+			if(!logs.isDirectory()) {
+				logs.delete();
+			}
+			if(!logs.exists()) {
+				logs.mkdirs();
+			}
+			Log4JLogIt logIt = new Log4JLogIt(log_dir,log_level,propsFile, "fs");
+			PropAccess propAccess = new PropAccess(logIt,args);
+ 		
  			AAF_FS service = new AAF_FS(new AuthzEnv(propAccess));
-//			env.setLog4JNames("log4j.properties","authz","fs","audit","init",null);
 			JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
 			jss.insecure().start();
 		} catch (Exception e) {
diff --git a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/AAF_GUI.java b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/AAF_GUI.java
index be93d63..676866b 100644
--- a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/AAF_GUI.java
+++ b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/AAF_GUI.java
@@ -25,6 +25,8 @@
 import static org.onap.aaf.auth.rserv.HttpMethods.POST;
 import static org.onap.aaf.auth.rserv.HttpMethods.PUT;
 
+import java.io.File;
+
 import javax.servlet.Filter;
 
 import org.onap.aaf.auth.cmd.Cmd;
@@ -68,6 +70,7 @@
 import org.onap.aaf.auth.rserv.CachingFileAccess;
 import org.onap.aaf.auth.server.AbsService;
 import org.onap.aaf.auth.server.JettyServiceStarter;
+import org.onap.aaf.auth.server.Log4JLogIt;
 import org.onap.aaf.cadi.CadiException;
 import org.onap.aaf.cadi.LocatorException;
 import org.onap.aaf.cadi.PropAccess;
@@ -254,10 +257,21 @@
 	}
 
 	public static void main(final String[] args) {
-		PropAccess propAccess = new PropAccess(args);
 		try {
- 			AAF_GUI service = new AAF_GUI(new AuthzEnv(propAccess));
-//			env.setLog4JNames("log4j.properties","authz","gui","audit","init","trace ");
+			String propsFile = getArg(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props";
+			String log_dir = getArg(Config.CADI_LOGDIR,args,"./logs");
+			String log_level = getArg(Config.CADI_LOGLEVEL,args,"INFO");
+			File logs = new File(log_dir);
+			if(!logs.isDirectory()) {
+				logs.delete();
+			}
+			if(!logs.exists()) {
+				logs.mkdirs();
+			}
+			Log4JLogIt logIt = new Log4JLogIt(log_dir,log_level,propsFile, "authz");
+			PropAccess propAccess = new PropAccess(logIt,args);
+ 		
+			AAF_GUI service = new AAF_GUI(new AuthzEnv(propAccess));
 			JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
 			jss.start();
 		} catch (Exception e) {
diff --git a/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/AAF_Hello.java b/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/AAF_Hello.java
index 97448bd..b20bf16 100644
--- a/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/AAF_Hello.java
+++ b/auth/auth-hello/src/main/java/org/onap/aaf/auth/hello/AAF_Hello.java
@@ -22,6 +22,7 @@
 
 package org.onap.aaf.auth.hello;
 
+import java.io.File;
 import java.util.Map;
 
 import javax.servlet.Filter;
@@ -34,6 +35,7 @@
 import org.onap.aaf.auth.rserv.HttpMethods;
 import org.onap.aaf.auth.server.AbsService;
 import org.onap.aaf.auth.server.JettyServiceStarter;
+import org.onap.aaf.auth.server.Log4JLogIt;
 import org.onap.aaf.cadi.CadiException;
 import org.onap.aaf.cadi.LocatorException;
 import org.onap.aaf.cadi.PropAccess;
@@ -116,10 +118,21 @@
 	}
 
 	public static void main(final String[] args) {
-		PropAccess propAccess = new PropAccess(args);
 		try {
+			String propsFile = getArg(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props";
+			String log_dir = getArg(Config.CADI_LOGDIR,args,"./logs");
+			String log_level = getArg(Config.CADI_LOGLEVEL,args,"INFO");
+			File logs = new File(log_dir);
+			if(!logs.isDirectory()) {
+				logs.delete();
+			}
+			if(!logs.exists()) {
+				logs.mkdirs();
+			}
+			Log4JLogIt logIt = new Log4JLogIt(log_dir,log_level,propsFile, "hello");
+			PropAccess propAccess = new PropAccess(logIt,args);
+ 		
  			AAF_Hello service = new AAF_Hello(new AuthzEnv(propAccess));
-//			env.setLog4JNames("log4j.properties","authz","hello","audit","init","trace");
 			JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
 			jss.start();
 		} catch (Exception e) {
diff --git a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java
index 92fc88c..31f6772 100644
--- a/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java
+++ b/auth/auth-locate/src/main/java/org/onap/aaf/auth/locate/AAF_Locate.java
@@ -22,6 +22,7 @@
 
 package org.onap.aaf.auth.locate;
 
+import java.io.File;
 import java.net.URI;
 import java.util.Map;
 
@@ -46,6 +47,7 @@
 import org.onap.aaf.auth.rserv.HttpMethods;
 import org.onap.aaf.auth.server.AbsService;
 import org.onap.aaf.auth.server.JettyServiceStarter;
+import org.onap.aaf.auth.server.Log4JLogIt;
 import org.onap.aaf.cadi.CadiException;
 import org.onap.aaf.cadi.Locator;
 import org.onap.aaf.cadi.LocatorException;
@@ -230,10 +232,21 @@
 	}
 
 	public static void main(final String[] args) {
-		PropAccess propAccess = new PropAccess(args);
 		try {
+			String propsFile = getArg(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props";
+			String log_dir = getArg(Config.CADI_LOGDIR,args,"./logs");
+			String log_level = getArg(Config.CADI_LOGLEVEL,args,"INFO");
+			File logs = new File(log_dir);
+			if(!logs.isDirectory()) {
+				logs.delete();
+			}
+			if(!logs.exists()) {
+				logs.mkdirs();
+			}
+			Log4JLogIt logIt = new Log4JLogIt(log_dir,log_level,propsFile, "locate");
+			PropAccess propAccess = new PropAccess(logIt,args);
+
  			AAF_Locate service = new AAF_Locate(new AuthzEnv(propAccess));
-// 			service.env().setLog4JNames("log4j.properties","authz","gw","audit","init","trace");
 			JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
 			jss.start();
 		} catch (Exception e) {
diff --git a/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/AAF_OAuth.java b/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/AAF_OAuth.java
index 1dac22f..846d1a5 100644
--- a/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/AAF_OAuth.java
+++ b/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/AAF_OAuth.java
@@ -22,6 +22,7 @@
 
 package org.onap.aaf.auth.oauth;
 
+import java.io.File;
 import java.util.Map;
 
 import javax.servlet.Filter;
@@ -45,6 +46,7 @@
 import org.onap.aaf.auth.rserv.HttpMethods;
 import org.onap.aaf.auth.server.AbsService;
 import org.onap.aaf.auth.server.JettyServiceStarter;
+import org.onap.aaf.auth.server.Log4JLogIt;
 import org.onap.aaf.cadi.CadiException;
 import org.onap.aaf.cadi.LocatorException;
 import org.onap.aaf.cadi.PropAccess;
@@ -183,10 +185,21 @@
 	}
 
 	public static void main(final String[] args) {
-		PropAccess propAccess = new PropAccess(args);
 		try {
+			String propsFile = getArg(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props";
+			String log_dir = getArg(Config.CADI_LOGDIR,args,"./logs");
+			String log_level = getArg(Config.CADI_LOGLEVEL,args,"INFO");
+			File logs = new File(log_dir);
+			if(!logs.isDirectory()) {
+				logs.delete();
+			}
+			if(!logs.exists()) {
+				logs.mkdirs();
+			}
+			Log4JLogIt logIt = new Log4JLogIt(log_dir,log_level,propsFile, "oauth");
+			PropAccess propAccess = new PropAccess(logIt,args);
+ 		
  			AAF_OAuth service = new AAF_OAuth(new AuthzEnv(propAccess));
-//			env.setLog4JNames("log4j.properties","authz","oauth","audit","init","trace");
 			JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
 			jss.start();
 		} catch (Exception e) {
diff --git a/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/DirectOAuthTAF.java b/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/DirectOAuthTAF.java
index e602e86..16d7268 100644
--- a/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/DirectOAuthTAF.java
+++ b/auth/auth-oauth/src/main/java/org/onap/aaf/auth/oauth/DirectOAuthTAF.java
@@ -101,6 +101,7 @@
 		}
 
 		if("application/x-www-form-urlencoded".equals(req.getContentType())) {
+			@SuppressWarnings("unchecked")
 			Map<String, String[]> map = req.getParameterMap();
 			String client_id=null,client_secret=null,username=null,password=null;
 			for(Map.Entry<String, String[]> es : map.entrySet()) {
diff --git a/auth/auth-service/.gitignore b/auth/auth-service/.gitignore
index 6028f0a..f3bad09 100644
--- a/auth/auth-service/.gitignore
+++ b/auth/auth-service/.gitignore
@@ -2,3 +2,4 @@
 /.settings/
 /target/
 /.project
+/logs/
diff --git a/auth/auth-service/pom.xml b/auth/auth-service/pom.xml
index 7f806f8..4acec25 100644
--- a/auth/auth-service/pom.xml
+++ b/auth/auth-service/pom.xml
@@ -28,7 +28,6 @@
 	<properties>
 		<maven.test.failure.ignore>true</maven.test.failure.ignore>
 		<!-- SONAR -->
-		<sonar.skip>true</sonar.skip>
 		<jacoco.version>0.7.7.201606060606</jacoco.version>
 		<sonar-jacoco-listeners.version>3.2</sonar-jacoco-listeners.version>
 		<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
@@ -90,11 +89,6 @@
 			<artifactId>jetty-servlet</artifactId>
 		</dependency>
 
-		<dependency>
-			<groupId>org.slf4j</groupId>
-			<artifactId>slf4j-log4j12</artifactId>
-		</dependency>
-
 	</dependencies>
 
 	<build>
diff --git a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AAF_Service.java b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AAF_Service.java
index ad9ccc4..0040912 100644
--- a/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AAF_Service.java
+++ b/auth/auth-service/src/main/java/org/onap/aaf/auth/service/AAF_Service.java
@@ -21,6 +21,8 @@
 
 package org.onap.aaf.auth.service;
 
+import java.io.File;
+
 import javax.servlet.Filter;
 
 import org.onap.aaf.auth.cache.Cache;
@@ -38,6 +40,7 @@
 import org.onap.aaf.auth.rserv.HttpMethods;
 import org.onap.aaf.auth.server.AbsService;
 import org.onap.aaf.auth.server.JettyServiceStarter;
+import org.onap.aaf.auth.server.Log4JLogIt;
 import org.onap.aaf.auth.service.api.API_Api;
 import org.onap.aaf.auth.service.api.API_Approval;
 import org.onap.aaf.auth.service.api.API_Creds;
@@ -59,6 +62,7 @@
 import org.onap.aaf.cadi.config.Config;
 import org.onap.aaf.cadi.register.Registrant;
 import org.onap.aaf.cadi.taf.basic.BasicHttpTaf;
+import org.onap.aaf.cadi.util.FQI;
 import org.onap.aaf.misc.env.APIException;
 import org.onap.aaf.misc.env.Data;
 import org.onap.aaf.misc.env.Env;
@@ -68,12 +72,8 @@
 public class AAF_Service extends AbsService<AuthzEnv,AuthzTrans> {
 
 	private static final String ORGANIZATION = "Organization.";
-	private static final String DOMAIN = "aaf.att.com";
 
-// TODO Add Service Metrics
-//	private Metric serviceMetric;
 	public final Question question;
-//	private final SessionFilter sessionFilter;
 	private AuthzFacade_2_0 facade;
 	private AuthzFacade_2_0 facade_XML;
 	private DirectAAFUserPass directAAFUserPass;
@@ -160,13 +160,14 @@
 	
 	@Override
 	public Filter[] filters() throws CadiException {
+		final String domain = FQI.reverseDomain(access.getProperty("aaf_root_ns","org.osaaf.aaf"));
 		try {
 				return new Filter[] {new AuthzTransFilter(env, null /* no connection to AAF... it is AAF */,
 						new AAFTrustChecker((Env)env),
 						new DirectAAFLur(env,question), // Note, this will be assigned by AuthzTransFilter to TrustChecker
 						//new DirectOAuthTAF(env,question,OAFacadeFactory.directV1_0(oauthService)),
 						new BasicHttpTaf(env, directAAFUserPass,
-							DOMAIN,Long.parseLong(env.getProperty(Config.AAF_CLEAN_INTERVAL, Config.AAF_CLEAN_INTERVAL_DEF)),
+							domain,Long.parseLong(env.getProperty(Config.AAF_CLEAN_INTERVAL, Config.AAF_CLEAN_INTERVAL_DEF)),
 							false)
 					)};
 		} catch (NumberFormatException e) {
@@ -214,10 +215,21 @@
 	 * Start up AAF_Service as Jetty Service
 	 */
 	public static void main(final String[] args) {
-		PropAccess propAccess = new PropAccess(args);
 		try {
- 			AAF_Service service = new AAF_Service(new AuthzEnv(propAccess));
-// 			service.env().setLog4JNames("log4j.properties","authz","authz|service","audit","init","trace");
+			String propsFile = getArg(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props";
+			String log_dir = getArg(Config.CADI_LOGDIR,args,"./logs");
+			String log_level = getArg(Config.CADI_LOGLEVEL,args,"INFO");
+			File logs = new File(log_dir);
+			if(!logs.isDirectory()) {
+				logs.delete();
+			}
+			if(!logs.exists()) {
+				logs.mkdirs();
+			}
+			Log4JLogIt logIt = new Log4JLogIt(log_dir,log_level,propsFile, "authz");
+			PropAccess propAccess = new PropAccess(logIt,args);
+ 		
+ 			AbsService<AuthzEnv, AuthzTrans> service = new AAF_Service(new AuthzEnv(propAccess));
 			JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
 			jss.start();
 		} catch (Exception e) {
diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java b/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java
index 7a9e63b..8312723 100644
--- a/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java
+++ b/cadi/core/src/main/java/org/onap/aaf/cadi/Access.java
@@ -37,7 +37,7 @@
 public interface Access {
 	// levels to use
 	public enum Level {
-		DEBUG(0x1), INFO(0x10), AUDIT(0x100), WARN(0x2000), ERROR(0x4000), INIT(0x8000),NONE(0XFFFF);
+		DEBUG(0x1), INFO(0x10), AUDIT(0x100), WARN(0x2000), ERROR(0x4000), INIT(0x8000),TRACE(0x10000),NONE(0XFFFF);
 		private final int bit;
 		
 		Level(int ord) {
diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java b/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java
index bd1ad72..c827477 100644
--- a/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java
+++ b/cadi/core/src/main/java/org/onap/aaf/cadi/PropAccess.java
@@ -31,12 +31,11 @@
 import java.util.Date;
 import java.util.List;
 import java.util.Map.Entry;
+import java.util.Properties;
 
 import org.onap.aaf.cadi.config.Config;
 import org.onap.aaf.cadi.config.SecurityInfo;
 
-import java.util.Properties;
-
 public class PropAccess implements Access {
 	// 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");
@@ -70,18 +69,11 @@
 	
 	public PropAccess(PrintStream ps, String[] args) {
 		logIt = new StreamLogIt(ps==null?System.out:ps);
-		Properties nprops=new Properties();
-		int eq;
-		for(String arg : args) {
-			if((eq=arg.indexOf('='))>0) {
-				nprops.setProperty(arg.substring(0, eq),arg.substring(eq+1));
-			}
-		}
-		init(nprops);
+		init(logIt,args);
 	}
 	
 	public PropAccess(LogIt logit, String[] args) {
-		logIt = logit;
+		init(logit, args);
 	}
 	
 	public PropAccess(Properties p) {
@@ -93,6 +85,18 @@
 		init(p);
 	}
 	
+	protected void init(final LogIt logIt, final String[] args) {
+		this.logIt = logIt;
+		Properties nprops=new Properties();
+		int eq;
+		for(String arg : args) {
+			if((eq=arg.indexOf('='))>0) {
+				nprops.setProperty(arg.substring(0, eq),arg.substring(eq+1));
+			}
+		}
+		init(nprops);
+	}
+	
 	protected void init(Properties p) {
 		// Make sure these two are set before any changes in Logging
 		name = "cadi";
@@ -248,9 +252,13 @@
 			logIt.push(level,elements);
 		}
 	}
-	
+
 	protected StringBuilder buildMsg(Level level, Object[] elements) {
-		StringBuilder sb = new StringBuilder(iso8601.format(new Date()));
+		return buildMsg(name,iso8601,level,elements);
+	}
+
+	public static StringBuilder buildMsg(final String name, final SimpleDateFormat sdf, Level level, Object[] elements) { 
+		StringBuilder sb = new StringBuilder(sdf.format(new Date()));
 		sb.append(' ');
 		sb.append(level.name());
 		sb.append(" [");
diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java b/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java
index 65cb81a..82645c3 100644
--- a/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java
+++ b/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java
@@ -452,7 +452,8 @@
 		   switch(read) {
 			   case -1: 
 			   case '=':
-			   case '\n': 
+			   case '\n':
+			   case '\r':
 				   return -1;
 		   }
 		   for(int i=0;i<range.length;++i) {
diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java
index 0c01154..0de6f4e 100644
--- a/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java
+++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java
@@ -73,6 +73,7 @@
 	public static final String HOSTNAME = "hostname";
 	public static final String CADI_PROP_FILES = "cadi_prop_files"; // Additional Properties files (separate with ;)
 	public static final String CADI_LOGLEVEL = "cadi_loglevel";
+	public static final String CADI_LOGDIR = "cadi_logdir";
 	public static final String CADI_LOGNAME = "cadi_logname";
 	public static final String CADI_KEYFILE = "cadi_keyfile";
 	public static final String CADI_KEYSTORE = "cadi_keystore";
@@ -82,6 +83,7 @@
 	public static final String CADI_LATITUDE = "cadi_latitude";
 	public static final String CADI_LONGITUDE = "cadi_longitude";
 
+
 	public static final String CADI_KEY_PASSWORD = "cadi_key_password";
 	public static final String CADI_TRUSTSTORE = "cadi_truststore";
 	public static final String CADI_TRUSTSTORE_PASSWORD = "cadi_truststore_password";
diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Access.java b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Access.java
index d62144c..9890356 100644
--- a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Access.java
+++ b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Access.java
@@ -44,7 +44,7 @@
 		assertThat(Level.DEBUG.delFromMask(0x1), is(0x0));
 		assertThat(Level.DEBUG.toggle(0x2), is(0x3));
 		assertThat(Level.DEBUG.toggle(0x1), is(0x0));
-		assertThat(Level.DEBUG.maskOf(), is(57617));
+		assertThat(Level.DEBUG.maskOf(), is(123153));
 		assertThat(Level.NONE.maskOf(), is(0));
 	}
 
diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CmdLine.java b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CmdLine.java
index 533fe91..b2820db 100644
--- a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CmdLine.java
+++ b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_CmdLine.java
@@ -32,6 +32,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintStream;
@@ -42,6 +43,7 @@
 import org.onap.aaf.cadi.CmdLine;
 import org.onap.aaf.cadi.PropAccess;
 import org.onap.aaf.cadi.Symm;
+import org.onap.aaf.cadi.util.Chmod;
 
 public class JU_CmdLine {
 
@@ -67,11 +69,30 @@
 		p.setProperty("force_exit", "false");
 
 		CmdLine.access = new PropAccess(p);
-
-		password = "password";
+		File test = new File("test");
+		if(test.exists()) {
+			if(!test.isDirectory()) {
+				test.delete();
+				test.mkdirs();
+			}
+		} else {
+			test.mkdirs();
+		}
+		
+		File keyF= new File(test,"keyfile");
+		if(!keyF.exists()) {
+			FileOutputStream fos = new FileOutputStream(keyF);
+			try {
+				fos.write(Symm.keygen());
+				fos.flush();
+			} finally {
+				fos.close();
+			}
+		}
 		keyfile = "test/keyfile";
+		password = "password";
 
-		FileInputStream fis = new FileInputStream(keyfile);
+		FileInputStream fis = new FileInputStream(keyF);
 		try {
 			symm = Symm.obtain(fis);
 		} finally {
diff --git a/misc/log4j/src/main/java/org/onap/aaf/misc/env/log4j/LogFileNamer.java b/misc/log4j/src/main/java/org/onap/aaf/misc/env/log4j/LogFileNamer.java
index 7174912..ff7b43f 100644
--- a/misc/log4j/src/main/java/org/onap/aaf/misc/env/log4j/LogFileNamer.java
+++ b/misc/log4j/src/main/java/org/onap/aaf/misc/env/log4j/LogFileNamer.java
@@ -22,56 +22,68 @@
 package org.onap.aaf.misc.env.log4j;
 
 import java.io.File;
+import java.io.IOException;
 import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
 public class LogFileNamer {
-	public final String root;
+	private final String root;
+	private final String ending;
+	private final String dir; 
 	
-	public LogFileNamer(String root) {
+	public LogFileNamer(final String dir, final String root) {
+		this.dir = dir;
 		if(root==null || "".equals(root) || root.endsWith("/")) {
 			this.root = root;
 		} else {
 			this.root = root + "-";
 		}
+		ending = new SimpleDateFormat("YYYYMMdd").format(new Date());
 	}
 	
 	public LogFileNamer noPID() {
 		return this;
 	}
+	
+	private static final String FILE_FORMAT_STR = "%s/%s%s%s_%d.log";
 	/**
 	 * Accepts a String.
 	 * If Separated by "|" then first part is the Appender name, and the second is used in the FileNaming
 	 * (This is to allow for shortened Logger names, and more verbose file names)
+	 * ONAP: jna code has license issues.  Just do Date + Unique Number
 	 * 
 	 * @param appender
 	 * 
 	 * returns the String Appender
+	 * @throws IOException 
 	 */
-	public String setAppender(String appender) {
-		int pipe = appender.indexOf('|');
-		if(pipe>=0) {
-			String rv;
-			System.setProperty(
-				"LOG4J_FILENAME_"+(rv=appender.substring(0,pipe)),
-				root + appender.substring(pipe+1) + ".log");
-			return rv;
-		} else {
-			System.setProperty(
-				"LOG4J_FILENAME_"+appender,
-				root + appender + ".log");
-			return appender;
-		}
-		
+	public String setAppender(String appender) throws IOException {
+		String filename;
+		int i=0;
+		File f;
+		while((f=new File(filename=String.format(FILE_FORMAT_STR, dir,root, appender, ending,i))).exists()) {
+			++i;
+		};
+		f.createNewFile();
+		System.setProperty(
+			"LOG4J_FILENAME_"+(appender),
+			filename);
+		return appender;
 	}
 
-	public void configure(String props) {
+	public void configure(final String props, final String log_level) throws IOException {
 		String fname;
 		if(new File(fname="etc/"+props).exists()) {
 			org.apache.log4j.PropertyConfigurator.configureAndWatch(fname,60*1000L);
 		} else {
 			URL rsrc = ClassLoader.getSystemResource(props);
-			if(rsrc==null) System.err.println("Neither File: " + fname + " or resource on Classpath " + props + " exist" );
+			if(rsrc==null) {
+				String msg = "Neither File: " + fname + " or resource on Classpath " + props + " exist" ;
+				throw new IOException(msg);
+			}
 			org.apache.log4j.PropertyConfigurator.configure(rsrc);
 		}
+		
 	}
 }