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