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