1 17 package org.apache.ws.jaxme.logging; 18 19 import java.io.PrintWriter ; 20 import java.io.StringWriter ; 21 import java.util.Date ; 22 23 24 28 public class LoggerImpl implements Logger { 29 private final String cName; 30 private boolean loggingTime, loggingThread; 31 32 public LoggerImpl(String pCName) { 33 cName = pCName; 34 } 35 36 public boolean isLoggingTime() { 37 return loggingTime; 38 } 39 40 public boolean isLoggingThread() { 41 return loggingThread; 42 } 43 44 public void setLoggingTime(boolean pLoggingTime) { 45 loggingTime = pLoggingTime; 46 } 47 48 public void setLoggingThread(boolean pLoggingThread) { 49 loggingThread = pLoggingThread; 50 } 51 52 protected void log(String pMsg) { 53 System.err.println(pMsg); 54 } 55 56 protected void log(String pLevel, String pCName, String pMName, String pMsg) { 57 log(pLevel, pCName, pMName, new Object []{pMsg}); 58 } 59 60 protected void log(String pLevel, String pCName, String pMName, 61 String pMsg, Object [] pDetails) { 62 if (pDetails == null) { 63 log(pLevel, pCName, pMName, new Object []{pMsg}); 64 } else { 65 Object [] o = new Object [pDetails.length+1]; 66 o[0] = pMsg; 67 for (int i = 0; i < pDetails.length; i++) { 68 o[i+1] = pDetails[i]; 69 } 70 log(pLevel, pCName, pMName, o); 71 } 72 } 73 74 protected void log(String pLevel, String pCName, String pMName, 75 Object [] pDetails) { 76 StringBuffer sb = new StringBuffer (); 77 if (loggingTime) { 78 sb.append(new Date ()); 79 sb.append(", "); 80 } 81 if (loggingThread) { 82 sb.append(Thread.currentThread().getName()); 83 sb.append(", "); 84 } 85 sb.append(": "); 86 sb.append(pLevel).append(", ").append(pMName).append(", "); 87 if (pDetails != null) { 88 for (int i = 0; i < pDetails.length; i++) { 89 sb.append(", ").append(pDetails[i]); 90 } 91 } 92 log(sb.toString()); 93 } 94 95 public boolean isFinestEnabled() { return true; } 96 public boolean isFinerEnabled() { return true; } 97 public boolean isFineEnabled() { return true; } 98 public boolean isInfoEnabled() { return true; } 99 public boolean isWarnEnabled() { return true; } 100 public boolean isErrorEnabled() { return true; } 101 102 public void finest(String mName, String pMsg, Object [] pDetails) { 103 log("FINEST", cName, mName, pMsg, pDetails); 104 } 105 106 public void finest(String mName, String pMsg) { 107 log("FINEST", cName, mName, pMsg); 108 } 109 110 public void finest(String mName, String pMsg, Object pDetails) { 111 log("FINEST", cName, mName, new Object []{pMsg, pDetails}); 112 } 113 114 public void finer(String mName, String pMsg, Object [] pDetails) { 115 log("FINER", cName, mName, pMsg, pDetails); 116 } 117 118 public void finer(String mName, String pMsg) { 119 log("FINER", cName, mName, pMsg); 120 } 121 122 public void finer(String mName, String pMsg, Object pDetails) { 123 log("FINER", cName, mName, new Object []{pMsg, pDetails}); 124 } 125 126 public void fine(String mName, String pMsg, Object [] pDetails) { 127 log("FINE", cName, mName, pMsg, pDetails); 128 } 129 130 public void fine(String mName, String pMsg) { 131 log("FINE", cName, mName, pMsg); 132 } 133 134 public void fine(String mName, String pMsg, Object pDetails) { 135 log("FINE", cName, mName, new Object []{pMsg, pDetails}); 136 } 137 138 public void info(String mName, String pMsg, Object [] pDetails) { 139 log("INFO", cName, mName, pMsg, pDetails); 140 } 141 142 public void info(String mName, String pMsg) { 143 log("INFO", cName, mName, pMsg); 144 } 145 146 public void info(String mName, String pMsg, Object pDetails) { 147 log("INFO", cName, mName, new Object []{pMsg, pDetails}); 148 } 149 150 public void warn(String mName, String pMsg, Object [] pDetails) { 151 log("WARN", cName, mName, pMsg, pDetails); 152 } 153 154 public void warn(String mName, String pMsg) { 155 log("WARN", cName, mName, pMsg); 156 } 157 158 public void warn(String mName, String pMsg, Object pDetails) { 159 log("WARN", cName, mName, new Object []{pMsg, pDetails}); 160 } 161 162 public void error(String mName, String pMsg, Object [] pDetails) { 163 log("ERROR", cName, mName, pMsg, pDetails); 164 } 165 166 public void error(String mName, String pMsg) { 167 log("ERROR", cName, mName, pMsg); 168 } 169 170 public void error(String mName, String pMsg, Object pDetails) { 171 log("ERROR", cName, mName, new Object []{pMsg, pDetails}); 172 } 173 174 public void entering(String mName, Object [] pDetails) { 175 log("->", cName, mName, pDetails); 176 } 177 178 public void entering(String mName) { 179 log("->", cName, mName, (Object []) null); 180 } 181 182 public void entering(String mName, Object pDetails) { 183 log("->", cName, mName, new Object []{pDetails}); 184 } 185 186 public void exiting(String mName, Object [] pDetails) { 187 log("<-", cName, mName, pDetails); 188 } 189 190 public void exiting(String mName) { 191 log("<-", cName, mName, (Object []) null); 192 } 193 194 public void exiting(String mName, Object pDetails) { 195 log("<-", cName, mName, new Object []{pDetails}); 196 } 197 198 public void throwing(String mName, Throwable pThrowable) { 199 StringWriter sw = new StringWriter (); 200 pThrowable.printStackTrace(new PrintWriter (sw)); 201 log("THROWABLE", cName, mName, sw.toString()); 202 } 203 } 204 | Popular Tags |