1 16 package org.apache.pluto.portlet.admin; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 21 27 public class PlutoAdminLogger { 28 private static Log _log = LogFactory.getLog(PlutoAdminLogger.class); 29 private static final String MSG_SEP = " | "; 30 31 32 36 private PlutoAdminLogger() { 37 } 38 39 40 public static void logMethodStart(String className, String methodName) { 41 if (_log.isInfoEnabled()) { 42 _log.info(getLogMessage(className, methodName, "Start of method . . .")); 43 } 44 } 45 46 public static void logMethodEnd(String className, String methodName) { 47 if (_log.isInfoEnabled()) { 48 _log.info(getLogMessage(className, methodName, ". . .end of method")); 49 } 50 } 51 52 public static void logMethodEnd(String className, String methodName, Object retVal) { 53 if (_log.isInfoEnabled()) { 54 _log.info(getLogMessage(className, methodName, ". . .end of method with return value = " + (retVal == null ? "null" : retVal.toString()))); 55 } 56 } 57 58 public static void logParam(String className, String methodName, String paramName, Object paramVal) { 59 if (_log.isInfoEnabled()) { 60 _log.info(getLogMessage(className, methodName, "Parameter '" + paramName + "' has value=" + (paramVal == null ? "null" : paramVal.toString()))); 61 } 62 } 63 64 public static void logParam(String className, String methodName, String paramName, int paramVal) { 65 if (_log.isInfoEnabled()) { 66 _log.info(getLogMessage(className, methodName, "Parameter '" + paramName + "' has value=" + paramVal)); 67 } 68 } 69 70 public static void logParam(String className, String methodName, String paramName, boolean paramVal) { 71 if (_log.isInfoEnabled()) { 72 _log.info(getLogMessage(className, methodName, "Parameter '" + paramName + "' has value=" + (paramVal ? "true" : "false"))); 73 } 74 } 75 76 public static void logVar(String className, String methodName, String varName, Object varVal) { 77 if (_log.isDebugEnabled()) { 78 _log.debug(getLogMessage(className, methodName, "Variable '" + varName + "' has value=" + (varVal == null ? "null" : varVal.toString()))); 79 } 80 } 81 82 public static void logVar(String className, String methodName, String varName, int varVal) { 83 if (_log.isDebugEnabled()) { 84 _log.debug(getLogMessage(className, methodName, "Variable '" + varName + "' has value=" + varVal)); 85 } 86 } 87 88 public static void logVar(String className, String methodName, String varName, boolean varVal) { 89 if (_log.isDebugEnabled()) { 90 _log.debug(getLogMessage(className, methodName, "Variable '" + varName + "' has value=" + (varVal ? "true" : "false"))); 91 } 92 } 93 94 public static void logDebug(String className, String methodName, String msg) { 95 if (_log.isDebugEnabled()) { 96 _log.debug(getLogMessage(className, methodName, msg)); 97 } 98 } 99 100 public static void logWarn(String className, String methodName, String msg) { 101 if (_log.isWarnEnabled()) { 102 _log.warn(getLogMessage(className, methodName, msg)); 103 } 104 } 105 106 public static void logError(String className, String methodName, String msg, Throwable e) { 107 if (_log.isErrorEnabled()) { 108 _log.error(getLogMessage(className, methodName, msg), e); 109 } 110 } 111 112 public static void logError(String className, String methodName, Throwable e) { 113 if (_log.isErrorEnabled()) { 114 _log.error(getLogMessage(className, methodName, e != null ? e.toString() : ""), e); 115 } 116 } 117 118 public static void logError(String className, String methodName, String msg) { 119 if (_log.isErrorEnabled()) { 120 _log.error(getLogMessage(className, methodName, msg)); 121 } 122 } 123 124 private static String getLogMessage(String className, String methodName, String msg) { 125 StringBuffer retMsg = new StringBuffer (); 126 if (className == null) { 127 throw new IllegalStateException ("Null class name. Please set class name in the constructor."); 128 } 129 if (methodName == null) { 130 throw new IllegalArgumentException ("Null method name."); 131 } 132 retMsg.append(className); 137 retMsg.append("."); 138 retMsg.append(methodName); 139 retMsg.append(MSG_SEP); 140 retMsg.append(msg == null ? "" : msg); 141 return retMsg.toString(); 142 } 143 } 144 | Popular Tags |