2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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=========================================================
21 package org.onap.appc.ccadaptor;
23 import java.io.BufferedWriter;
25 import java.io.FileWriter;
26 import java.io.IOException;
27 import java.io.PrintWriter;
28 import java.io.StringWriter;
29 import java.text.DateFormat;
30 import java.text.SimpleDateFormat;
31 import java.util.Date;
34 public class DebugLog {
36 private static String fileName = "/tmp/rt.log";
38 public static void main(String args[]) {
39 DebugLog debugLog = new DebugLog();
40 debugLog.printAriDebug("DebugLog", "The Message");
43 public static void printAriDebug(String fn, String messg) {
44 String logMessg = getDateTime() + " " + fn + " " + messg;
45 appendToFile(logMessg + "\n");
49 public static void printRTAriDebug(String fn, String messg) {
50 // System.out.println (getDateTime() +" " +fn +" " + messg);
51 String logMessg = getDateTime() + " " + fn + " " + messg;
52 appendToFile(logMessg + "\n");
55 public static String getDateTime() {
56 DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
57 // DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
58 Date date = new Date();
59 return dateFormat.format(date);
62 public static void appendToFile(String dataToWrite) {
63 String fn = "DebugLog.appendToFile";
65 // First check to see if a file 'fileName' exist, if it does
66 // write to it. If it does not exist, don't write to it.
67 File tmpFile = new File(fileName);
68 if (tmpFile.exists()) {
69 BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));
70 out.write(dataToWrite);
73 } catch (IOException e) {
74 DebugLog.printRTAriDebug(fn, "writeToFile() exception: " + e);
75 //System.err.println("writeToFile() exception: " + e);
80 public void outputStackTrace(Exception e) {
81 String fn = "DebugLog.outputStackTrace";
82 StringWriter sw = new StringWriter();
83 e.printStackTrace(new PrintWriter(sw));
84 String stackTrace = sw.toString();
85 DebugLog.printRTAriDebug(fn, "Stack trace::: " + stackTrace);
88 public static String getStackTraceString(Exception e) {
89 String fn = "DebugLog.outputStackTrace";
90 StringWriter sw = new StringWriter();
91 e.printStackTrace(new PrintWriter(sw));
92 String stackTrace = sw.toString();