1 21 package oracle.toplink.essentials.logging; 23 24 import java.io.*; 25 import oracle.toplink.essentials.exceptions.*; 26 import oracle.toplink.essentials.internal.helper.*; 27 28 48 public class DefaultSessionLog extends AbstractSessionLog implements Serializable { 49 50 51 protected String fileName; 52 53 57 public DefaultSessionLog() { 58 super(); 59 this.level = INFO; 60 } 61 62 66 public DefaultSessionLog(Writer writer) { 67 this(); 68 this.initialize(writer); 69 } 70 71 74 protected void initialize(Writer writer) { 75 this.writer = writer; 76 } 77 78 84 public synchronized void log(SessionLogEntry entry) { 85 if (!shouldLog(entry.getLevel())) { 86 return; 87 } 88 89 try { 90 printPrefixString(entry.getLevel()); 91 this.getWriter().write(getSupplementDetailString(entry)); 92 93 if (entry.hasException()) { 94 if (entry.getLevel() == SEVERE) { 95 entry.getException().printStackTrace(new PrintWriter(getWriter())); 96 } else if (entry.getLevel() <= WARNING) { 97 if (shouldLogExceptionStackTrace()) { 98 entry.getException().printStackTrace(new PrintWriter(getWriter())); 99 } else { 100 writeMessage(entry.getException().toString()); 101 } 102 } 103 } else { 104 writeMessage(formatMessage(entry)); 105 } 106 getWriter().write(Helper.cr()); 107 getWriter().flush(); 108 } catch (IOException exception) { 109 throw ValidationException.logIOError(exception); 110 } 111 } 112 113 118 public void setWriter(String aFileName) { 119 if (aFileName != null) { 120 try { 121 this.writer = new FileWriter(aFileName); 122 this.fileName = aFileName; 123 } catch (IOException e) { 124 e.printStackTrace(); 125 } 126 } 127 } 128 129 134 public String getWriterFilename() { 135 return fileName; 136 } 137 138 141 protected void writeMessage(String message) throws IOException { 142 this.getWriter().write(message); 143 } 144 145 148 protected void writeSeparator() throws IOException { 149 this.getWriter().write("--"); 150 } 151 } 152 | Popular Tags |