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;
24 import java.text.DateFormat;
25 import java.text.SimpleDateFormat;
26 import java.util.Date;
31 private static String fileName = "/tmp/rt.log";
33 public static void main (String args[])
35 DebugLog debugLog = new DebugLog();
36 debugLog.printAriDebug("DebugLog", "The Message");
39 public static void printAriDebug(String fn, String messg)
41 String logMessg = getDateTime() +" " +fn +" " + messg;
42 appendToFile(logMessg +"\n");
46 public static void printRTAriDebug(String fn, String messg)
48 // System.out.println (getDateTime() +" " +fn +" " + messg);
49 String logMessg = getDateTime() +" " +fn +" " + messg;
50 appendToFile(logMessg +"\n");
52 public static String getDateTime()
54 DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
55 // DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
56 Date date = new Date();
57 return dateFormat.format(date);
60 public static void appendToFile (String dataToWrite)
62 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);
70 BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));
71 out.write(dataToWrite);
77 DebugLog.printRTAriDebug (fn, "writeToFile() exception: " + e);
78 //System.err.println("writeToFile() exception: " + e);
83 public void outputStackTrace(Exception e)
85 String fn = "DebugLog.outputStackTrace";
86 StringWriter sw = new StringWriter();
87 e.printStackTrace(new PrintWriter(sw));
88 String stackTrace = sw.toString();
89 DebugLog.printRTAriDebug(fn, "Stack trace::: "+stackTrace);
92 public static String getStackTraceString(Exception e)
94 String fn = "DebugLog.outputStackTrace";
95 StringWriter sw = new StringWriter();
96 e.printStackTrace(new PrintWriter(sw));
97 String stackTrace = sw.toString();