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