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;
24 import java.io.PrintStream;
25 import java.util.Date;
27 import org.onap.aaf.misc.env.util.Chrono;
30 * LogTarget is the interface with which to assign any kind of Logging Implementations.
32 * Implement for any Logging Library of your choice, and for any logging string Format desired.
34 * Included are several Static Implementations for various uses:
35 * NULL: Does nothing with Logging Messages
36 * SYSOUT: Writes messages in general form to System Out
37 * SYSERR: Writes messages in general form to System Err
42 public interface LogTarget {
43 public abstract void log(Object... msgs);
44 public abstract void log(Throwable e, Object ... msgs);
45 public abstract boolean isLoggable();
46 public abstract void printf(String fmt, Object ... vars);
48 // A Convenient LogTarget to insert when a NO-OP is desired.
49 public static final LogTarget NULL = new LogTarget() {
50 public void log(Object ... msgs) {
53 public void log(Throwable t, Object ... msgs) {
56 public boolean isLoggable() {
61 public void printf(String fmt, Object ... vars) {
65 // A Convenient LogTarget to write to the Console
66 public static final LogTarget SYSOUT = new LogTarget() {
67 public void log(Object ... msgs) {
68 PrintStream out = System.out;
69 out.print(org.onap.aaf.misc.env.util.Chrono.dateFmt.format(new Date()));
71 for(Object str : msgs) {
73 out.print(str.toString());
82 public void log(Throwable t, Object ... msgs) {
83 PrintStream out = System.out;
84 out.print(Chrono.dateFmt.format(new Date()));
86 for(Object str : msgs) {
87 out.print(str.toString());
91 t.printStackTrace(out);
95 public boolean isLoggable() {
100 public void printf(String fmt, Object ... vars) {
101 log(String.format(fmt,vars));
105 // A Convenient LogTarget to write to the Console
106 public static final LogTarget SYSERR = new LogTarget() {
107 public void log(Object ... msgs) {
108 PrintStream out = System.err;
109 out.print(Chrono.dateFmt.format(new Date()));
111 for(Object str : msgs) {
112 out.print(str.toString());
119 public void log(Throwable t, Object ... msgs) {
120 PrintStream out = System.err;
121 out.print(Chrono.dateFmt.format(new Date()));
123 for(Object str : msgs) {
124 out.print(str.toString());
128 t.printStackTrace(out);
131 public boolean isLoggable() {
135 public void printf(String fmt, Object ... vars) {
136 log(String.format(fmt,vars));