2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.misc.env.impl;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
27 import org.onap.aaf.misc.env.LogTarget;
30 * This LogTarget Implementation is included mostly because the JavaUtil based logging is included in the
31 * JDK. This makes the default implementation independent of any external Jars.
33 * Log4j is often considered more Enterprise capable. See Log4JLogTarget for that implementation
38 public class JavaUtilLogTarget implements LogTarget {
42 public JavaUtilLogTarget(Logger logger, Level theLevel) {
47 public boolean isLoggable() {
48 return log.isLoggable(level);
51 public void log(Object ... msgs) {
52 if(log.isLoggable(level)) {
53 StringBuilder sb = new StringBuilder();
55 for(int i=0;i<msgs.length;++i) {
56 msg = msgs[i].toString();
57 if(msg!=null && msg.length()>0) {
58 int sbl = sb.length();
60 char last = sb.charAt(sbl-1);
61 if(" (.".indexOf(last)<0 && "().".indexOf(msg.charAt(0))<0)sb.append(' ');
66 log.log(level, sb.toString());
70 public void log(Throwable e, Object ... msgs) {
71 String str = e.getLocalizedMessage();
76 str = e.getClass().getName();
78 log.log(level,str,msgs);
82 * @see com.att.inno.env.LogTarget#printf(java.lang.String, java.lang.String[])
85 public void printf(String fmt, Object ... vars) {
86 if(log.isLoggable(level)) {
87 log.log(level,String.format(fmt,vars));