2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
24 package org.onap.appc.ccadaptor;
26 import java.io.BufferedWriter;
28 import java.io.FileWriter;
29 import java.io.IOException;
30 import java.io.PrintWriter;
31 import java.io.StringWriter;
32 import java.text.DateFormat;
33 import java.text.SimpleDateFormat;
34 import java.util.Date;
37 public class DebugLog {
39 private static String fileName = "/tmp/rt.log";
41 public static void main(String args[]) {
42 DebugLog debugLog = new DebugLog();
43 debugLog.printAriDebug("DebugLog", "The Message");
46 public static void printAriDebug(String fn, String messg) {
47 String logMessg = getDateTime() + " " + fn + " " + messg;
48 appendToFile(logMessg + "\n");
52 public static void printRTAriDebug(String fn, String messg) {
53 // System.out.println (getDateTime() +" " +fn +" " + messg);
54 String logMessg = getDateTime() + " " + fn + " " + messg;
55 appendToFile(logMessg + "\n");
58 public static String getDateTime() {
59 DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
60 // DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
61 Date date = new Date();
62 return dateFormat.format(date);
65 public static void appendToFile(String dataToWrite) {
66 String fn = "DebugLog.appendToFile";
68 // First check to see if a file 'fileName' exist, if it does
69 // write to it. If it does not exist, don't write to it.
70 File tmpFile = new File(fileName);
71 if (tmpFile.exists()) {
72 BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));
73 out.write(dataToWrite);
76 } catch (IOException e) {
77 DebugLog.printRTAriDebug(fn, "writeToFile() exception: " + e);
78 //System.err.println("writeToFile() exception: " + e);
83 public void outputStackTrace(Exception e) {
84 String fn = "DebugLog.outputStackTrace";
85 StringWriter sw = new StringWriter();
86 e.printStackTrace(new PrintWriter(sw));
87 String stackTrace = sw.toString();
88 DebugLog.printRTAriDebug(fn, "Stack trace::: " + stackTrace);
91 public static String getStackTraceString(Exception e) {
92 String fn = "DebugLog.outputStackTrace";
93 StringWriter sw = new StringWriter();
94 e.printStackTrace(new PrintWriter(sw));
95 String stackTrace = sw.toString();