PageRenderTime 27ms CodeModel.GetById 12ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/webccr/src/com/emis/caesarui/webccr/webccrlog.java

https://bitbucket.org/sanliou/synccr
Java | 124 lines | 111 code | 10 blank | 3 comment | 13 complexity | 46bb3172590d082679cd061eb36c351a MD5 | raw file
  1package com.emis.caesarui.webccr;
  2
  3import com.emis.caesar.senao.util.CcrUtil;
  4import com.emis.util.emisUtil;
  5import com.vaadin.ui.UI;
  6
  7import java.io.File;
  8import java.io.FileWriter;
  9import java.util.Date;
 10
 11/**
 12 *
 13 */
 14public class webccrlog {
 15
 16  private String fileLogName = "";
 17
 18  public void init(String S_NO, String ID_NO) {
 19    String path = null;
 20    try {
 21      if (!"".equals(S_NO) && !"".equals(ID_NO)) {
 22        path = "/opt/logs/" + emisUtil.todayDate() + "/" + S_NO + "/" + ID_NO + "/";
 23      } else {
 24        path = "/opt/logs/" + emisUtil.todayDate() + "/";
 25      }
 26      emisUtil.mkdir(path);
 27      fileLogName = path;
 28    } catch (Exception e) {
 29      e.printStackTrace();
 30    }
 31  }
 32
 33  private String getFormatDateString() {
 34    return emisUtil.formatDateTime("%Y/%M/%D %h:%m:%s ", new Date());
 35  }
 36
 37  public void info(Class className, String message) {
 38    FileWriter fileWriter = null;
 39    try {
 40      fileWriter = new FileWriter(fileLogName + "/" + className.getName() + ".log", true);
 41      String sDate = getFormatDateString();
 42      fileWriter.write("INFO -" + sDate + ":" + message + "\r\n");
 43      CcrUtil.setMessage("INFO -" + sDate + ":" + message + "\r\n");
 44      fileWriter.flush();
 45    } catch (Exception ignored) {
 46    } finally {
 47      if (fileWriter != null) {
 48        try {
 49          fileWriter.close();
 50        } catch (Exception e) {
 51        }
 52      }
 53    }
 54  }
 55
 56  public void error(Class className, Throwable t) {
 57    FileWriter fileWriter = null;
 58    try {
 59      fileWriter = new FileWriter(fileLogName + "/" + className.getName() + ".log", true);
 60      String sDate = getFormatDateString();
 61      StackTraceElement[] elements = t.getStackTrace();
 62      fileWriter.write("ERROR-" + sDate + ":" + t.getMessage() + "\r\n");
 63      CcrUtil.setMessage("ERROR-" + sDate + ":" + t.getMessage() + "\r\n");
 64      for (int i = 0; i < elements.length; i++) {
 65        StackTraceElement se = elements[i];
 66        fileWriter.write(se.getClassName() + "." + se.getMethodName() + " LINE " + se.getLineNumber() + "\r\n");
 67        CcrUtil.setMessage(se.getClassName() + "." + se.getMethodName() + " LINE " + se.getLineNumber() + "\r\n");
 68      }
 69      fileWriter.flush();
 70    } catch (Exception ignored) {
 71    } finally {
 72      if (fileWriter != null) {
 73        try {
 74          fileWriter.close();
 75        } catch (Exception e) {
 76        }
 77      }
 78    }
 79  }
 80
 81  public void error(Class className, Exception e) {
 82    FileWriter fileWriter = null;
 83    try {
 84      fileWriter = new FileWriter(fileLogName + "/" + className.getName() + ".log", true);
 85      String sDate = getFormatDateString();
 86      StackTraceElement[] elements = e.getStackTrace();
 87      fileWriter.write("ERROR-" + sDate + ":" + e.getMessage() + "\r\n");
 88      CcrUtil.setMessage("ERROR-" + sDate + ":" + e.getMessage() + "\r\n");
 89      for (int i = 0; i < elements.length; i++) {
 90        StackTraceElement se = elements[i];
 91        fileWriter.write(se.getClassName() + "." + se.getMethodName() + " LINE " + se.getLineNumber() + "\r\n");
 92        CcrUtil.setMessage(se.getClassName() + "." + se.getMethodName() + " LINE " + se.getLineNumber() + "\r\n");
 93      }
 94      fileWriter.flush();
 95    } catch (Exception ignored) {
 96    } finally {
 97      if (fileWriter != null) {
 98        try {
 99          fileWriter.close();
100        } catch (Exception e1) {
101        }
102      }
103    }
104  }
105
106  public void error(Class className, String message) {
107    FileWriter fileWriter = null;
108    try {
109      fileWriter = new FileWriter(fileLogName + "/" + className.getName() + ".log", true);
110      String sDate = getFormatDateString();
111      fileWriter.write("ERROR-" + sDate + ":" + message + "\r\n");
112      CcrUtil.setMessage("ERROR-" + sDate + ":" + message + "\r\n");
113      fileWriter.flush();
114    } catch (Exception ignored) {
115    } finally {
116      if (fileWriter != null) {
117        try {
118          fileWriter.close();
119        } catch (Exception e1) {
120        }
121      }
122    }
123  }
124}