1 17 package org.apache.ws.jaxme.logging; 18 19 import org.apache.log4j.Level; 20 21 22 25 public class Log4jLogger implements Logger { 26 private final org.apache.log4j.Logger logger; 27 28 public Log4jLogger(String pCName) { 29 logger = org.apache.log4j.Logger.getLogger(pCName); 30 } 31 32 protected String format(String pMethodName, String pMsg, Object [] pDetails) { 33 final StringBuffer sb = new StringBuffer (pMethodName); 34 sb.append(": ").append(pMsg); 35 if (pDetails != null) { 36 for (int i = 0; i < pDetails.length; i++) { 37 sb.append(", "); 38 sb.append(pDetails[i]); 39 } 40 } 41 return sb.toString(); 42 } 43 44 protected String format(String pMethodName, Object [] pDetails) { 45 final StringBuffer sb = new StringBuffer (pMethodName); 46 if (pDetails != null) { 47 String add = ": "; 48 for (int i = 0; i < pDetails.length; i++) { 49 sb.append(add); 50 add = ", "; 51 sb.append(pDetails[i]); 52 } 53 } 54 return sb.toString(); 55 } 56 57 public void entering(String pMethodName, Object [] pDetails) { 58 if (logger.isDebugEnabled()) { 59 logger.debug(format(pMethodName + " ->", pDetails)); 60 } 61 } 62 63 public void entering(String pMethodName) { 64 if (logger.isDebugEnabled()) { 65 logger.debug(pMethodName + " ->"); 66 } 67 } 68 69 public void entering(String pMethodName, Object pDetails) { 70 if (logger.isDebugEnabled()) { 71 logger.debug(pMethodName + " ->: " + pDetails); 72 } 73 } 74 75 public void exiting(String pMethodName, Object [] pDetails) { 76 if (logger.isDebugEnabled()) { 77 logger.debug(format(pMethodName + " <-", pDetails)); 78 } 79 } 80 81 public void exiting(String pMethodName) { 82 if (logger.isDebugEnabled()) { 83 logger.debug(pMethodName + " <-"); 84 } 85 } 86 87 public void exiting(String pMethodName, Object pDetails) { 88 if (logger.isDebugEnabled()) { 89 logger.debug(pMethodName + " <-: " + pDetails); 90 } 91 } 92 93 public void throwing(String pMethodName, Throwable pThrowable) { 94 logger.error(pMethodName, pThrowable); 95 } 96 97 public boolean isFinestEnabled() { 98 return logger.isDebugEnabled(); 99 } 100 101 public void finest(String pMethodName, String pMsg, Object [] pDetails) { 102 if (logger.isDebugEnabled()) { 103 logger.debug(format(pMethodName, pMsg, pDetails)); 104 } 105 } 106 107 public void finest(String pMethodName, String pMsg) { 108 if (logger.isDebugEnabled()) { 109 logger.debug(pMethodName + ": " + pMsg); 110 } 111 } 112 113 public void finest(String pMethodName, String pMsg, Object pDetails) { 114 if (logger.isDebugEnabled()) { 115 logger.debug(pMethodName + ": " + pMsg + ", " + pDetails); 116 } 117 } 118 119 public void finer(String pMethodName, String pMsg, Object [] pDetails) { 120 finest(pMethodName, pMsg, pDetails); 121 } 122 123 public boolean isFinerEnabled() { 124 return isFinestEnabled(); 125 } 126 127 public void finer(String pMethodName, String pMsg) { 128 finest(pMethodName, pMsg); 129 } 130 131 public void finer(String pMethodName, String pMsg, Object pDetails) { 132 finest(pMethodName, pMsg, pDetails); 133 } 134 135 public boolean isFineEnabled() { 136 return isFinestEnabled(); 137 } 138 139 public void fine(String pMethodName, String pMsg, Object [] pDetails) { 140 finest(pMethodName, pMsg, pDetails); 141 } 142 143 public void fine(String pMethodName, String pMsg) { 144 finest(pMethodName, pMsg); 145 } 146 147 public void fine(String pMethodName, String pMsg, Object pDetails) { 148 finest(pMethodName, pMsg, pDetails); 149 } 150 151 public boolean isInfoEnabled() { 152 return logger.isInfoEnabled(); 153 } 154 155 public void info(String pMethodName, String pMsg, Object [] pDetails) { 156 if (logger.isInfoEnabled()) { 157 logger.info(format(pMethodName, pMsg, pDetails)); 158 } 159 } 160 161 public void info(String pMethodName, String pMsg) { 162 if (logger.isInfoEnabled()) { 163 logger.info(pMethodName + ": " + pMsg); 164 } 165 } 166 167 public void info(String pMethodName, String pMsg, Object pDetails) { 168 if (logger.isInfoEnabled()) { 169 logger.info(pMethodName + ": " + pMsg + ", " + pDetails); 170 } 171 } 172 173 public boolean isWarnEnabled() { 174 return logger.isEnabledFor(Level.WARN); 175 } 176 177 public void warn(String pMethodName, String pMsg, Object [] pDetails) { 178 if (logger.isEnabledFor(Level.WARN)) { 179 logger.warn(format(pMethodName, pMsg, pDetails)); 180 } 181 } 182 183 public void warn(String pMethodName, String pMsg) { 184 if (logger.isEnabledFor(Level.WARN)) { 185 logger.warn(pMethodName + ": " + pMsg); 186 } 187 } 188 189 public void warn(String pMethodName, String pMsg, Object pDetails) { 190 if (logger.isEnabledFor(Level.WARN)) { 191 logger.warn(pMethodName + ": " + pMsg + ", " + pDetails); 192 } 193 } 194 195 public boolean isErrorEnabled() { 196 return logger.isEnabledFor(Level.ERROR); 197 } 198 199 public void error(String pMethodName, String pMsg, Object [] pDetails) { 200 if (logger.isEnabledFor(Level.ERROR)) { 201 logger.error(format(pMethodName, pMsg, pDetails)); 202 } 203 } 204 205 public void error(String pMethodName, String pMsg) { 206 if (logger.isEnabledFor(Level.ERROR)) { 207 logger.error(pMethodName + ": " + pMsg); 208 } 209 } 210 211 public void error(String pMethodName, String pMsg, Object pDetails) { 212 if (logger.isEnabledFor(Level.ERROR)) { 213 logger.error(pMethodName + ": " + pMsg + ", " + pDetails); 214 } 215 } 216 } 217 | Popular Tags |