1 19 27 28 package org.netbeans.modules.exceptions; 29 30 import java.io.File ; 31 import java.io.FileWriter ; 32 import java.io.IOException ; 33 import java.io.Writer ; 34 import java.util.logging.Formatter ; 35 import java.util.logging.Handler ; 36 import java.util.logging.LogRecord ; 37 import java.util.logging.SimpleFormatter ; 38 42 public class ExceptionsLoggingHandler extends Handler { 43 public static boolean logOUT = false; 44 private File logFile = null; 45 private FileWriter writer = null; 46 private Formatter formatter = new SimpleFormatter (); 47 48 49 public ExceptionsLoggingHandler() { 50 } 51 52 public void publish(LogRecord arg0) { 53 try { 54 getWriter().write(formatter.format(arg0)); 55 if (logOUT) System.out.print(formatter.format(arg0)); 56 } 57 catch (IOException ex) { 58 java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, 59 ex.getMessage(), ex); 60 } 61 } 62 63 public void flush(){ 64 try { 65 getWriter().flush(); 66 } catch (IOException ex) { 67 java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, 68 ex.getMessage(), ex); 69 } 70 } 71 72 public void close() throws SecurityException { 73 try { 74 flush(); 75 getWriter().close(); 76 } catch (IOException ex) { 77 java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE, 78 ex.getMessage(), ex); 79 } 80 } 81 82 private Writer getWriter() throws IOException { 83 if (logFile == null) 84 logFile = new File ("../logs/ExceptionsLogging.log"); 85 if (writer == null) 86 writer = new FileWriter (logFile); 87 return writer; 88 } 89 90 } 91 | Popular Tags |