1 11 package org.eclipse.help.internal.browser; 12 13 import java.io.*; 14 import com.ibm.icu.text.DateFormat; 15 import com.ibm.icu.text.SimpleDateFormat; 16 import java.util.Date ; 17 18 import org.eclipse.help.internal.base.*; 19 20 23 public class BrowserLog { 24 private static BrowserLog instance; 25 private String logFileName; 26 private boolean newSession; 27 DateFormat formatter = new SimpleDateFormat("MMM dd, yyyy kk:mm:ss.SS"); String LN = System.getProperty("line.separator"); 32 private BrowserLog() { 33 try { 34 newSession = true; 35 logFileName = HelpBasePlugin.getDefault().getStateLocation() 36 .append("browser.log") .toOSString(); 38 } catch (Exception e) { 39 } 41 } 42 45 private static BrowserLog getInstance() { 46 if (instance == null) { 47 instance = new BrowserLog(); 48 } 49 return instance; 50 } 51 54 public static synchronized void log(String message) { 55 getInstance().append(message); 56 } 57 private void append(String message) { 58 if (logFileName == null) { 59 return; 60 } 61 Writer outWriter = null; 62 try { 63 outWriter = new BufferedWriter(new OutputStreamWriter( 64 new FileOutputStream(logFileName, true), "UTF-8")); if (newSession) { 66 newSession = false; 67 outWriter.write(LN + formatter.format(new Date ()) 68 + " NEW SESSION" + LN); } 70 outWriter.write(formatter.format(new Date ()) + " " + message + LN); outWriter.flush(); 72 outWriter.close(); 73 } catch (Exception e) { 74 if (outWriter != null) { 75 try { 76 outWriter.close(); 77 } catch (IOException ioe) { 78 } 79 } 80 } 81 } 82 } 83 | Popular Tags |