다음과 같이 class를 만들어서 import하면
TraceLog.DataLog(" Log Data ");
와 같은 method를 통해서 file Log를 남길수 있다.
package com.sds.smb.component.sa.emul; import java.io.FileWriter; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; public class TraceLog{ //public static String m_PathName = Util.LOG_FILE_PATH;
public static String m_FileName = "DataLog"; private static FileWriter objfile = null; /*************************** * Logging Method * ***************************/ public static void DataLog(String log) { String stPath = ""; String stFileName = "";
String m_PathName = "/LOGS/smb/DataLog/"; stPath = m_PathName; stFileName = m_FileName; SimpleDateFormat formatter1 = new SimpleDateFormat ("MM-dd"); SimpleDateFormat formatter2 = new SimpleDateFormat ("HH:mm:ss");
String stDate = formatter1.format(new Date()); String stTime = formatter2.format(new Date()); StringBuffer bufLogPath = new StringBuffer(); bufLogPath.append(stPath); bufLogPath.append(stFileName); bufLogPath.append("_"); bufLogPath.append(stDate); bufLogPath.append(".log") ; StringBuffer bufLogMsg = new StringBuffer(); bufLogMsg.append("["); bufLogMsg.append(stDate); bufLogMsg.append(" "); bufLogMsg.append(stTime); bufLogMsg.append("]-"); bufLogMsg.append(log); // bufLogMsg.append("\r\n");
try{ objfile = new FileWriter(bufLogPath.toString(), true); objfile.write(bufLogMsg.toString()); objfile.write("\r\n"); }catch(IOException e){
} finally { try{ objfile.close(); }catch(Exception e1){} } } } |