1 23 24 package org.enhydra.xml.xmlc.servlet; 25 26 import java.io.PrintWriter ; 27 28 import javax.servlet.ServletContext ; 29 30 import org.enhydra.xml.xmlc.XMLCLogger; 31 32 35 class ServletXMLCLogger implements XMLCLogger { 36 39 private ServletContext fServletContext; 40 41 44 private PrintWriter fInfoWriter; 45 46 49 private PrintWriter fDebugWriter; 50 51 54 private PrintWriter fErrorWriter; 55 56 59 public ServletXMLCLogger(ServletContext servletContext, 60 boolean enableInfoLogging, 61 boolean enableDebugLogging) { 62 fServletContext = servletContext; 63 64 PrintWriter writer = new PrintWriter (new ServletLogWriter(fServletContext), 66 true); 67 if (enableInfoLogging) { 68 fInfoWriter = writer; 69 } 70 if (enableDebugLogging) { 71 fDebugWriter = writer; 72 } 73 fErrorWriter = writer; 74 } 75 76 79 public boolean infoEnabled() { 80 return (fInfoWriter != null); 81 } 82 83 86 public PrintWriter getInfoWriter() { 87 return fInfoWriter; 88 } 89 90 93 public void logInfo(String msg) { 94 if (fInfoWriter != null) { 95 fServletContext.log(msg); 96 } 97 } 98 99 102 public void logInfo(String msg, 103 Throwable except) { 104 if (fInfoWriter != null) { 105 fServletContext.log(msg, except); 106 } 107 } 108 109 112 public boolean errorEnabled() { 113 return (fErrorWriter != null); 114 } 115 116 119 public PrintWriter getErrorWriter() { 120 return fErrorWriter; 121 } 122 123 126 public void logError(String msg) { 127 if (fErrorWriter != null) { 128 fServletContext.log(msg); 129 } 130 } 131 132 135 public void logError(String msg, 136 Throwable except) { 137 if (fErrorWriter != null) { 138 fServletContext.log(msg, except); 139 } 140 } 141 142 145 public boolean debugEnabled() { 146 return (fDebugWriter != null); 147 } 148 149 152 public PrintWriter getDebugWriter() { 153 return fDebugWriter; 154 } 155 156 159 public void logDebug(String msg) { 160 if (fDebugWriter != null) { 161 fServletContext.log(msg); 162 } 163 } 164 165 168 public void logDebug(String msg, 169 Throwable except) { 170 if (fDebugWriter != null) { 171 fServletContext.log(msg, except); 172 } 173 } 174 } 175 | Popular Tags |