1 15 package org.apache.hivemind.service.impl; 16 17 import org.apache.commons.logging.Log; 18 import org.apache.hivemind.service.ClassFabUtils; 19 20 26 public class LoggingUtils 27 { 28 private static final int BUFFER_SIZE = 100; 29 30 public static void entry(Log log, String methodName, Object [] args) 31 { 32 StringBuffer buffer = new StringBuffer (BUFFER_SIZE); 33 34 buffer.append("BEGIN "); 35 buffer.append(methodName); 36 buffer.append("("); 37 38 int count = (args == null) ? 0 : args.length; 39 40 for (int i = 0; i < count; i++) 41 { 42 Object arg = args[i]; 43 44 if (i > 0) 45 buffer.append(", "); 46 47 convert(buffer, arg); 48 } 49 50 buffer.append(")"); 51 52 log.debug(buffer.toString()); 53 } 54 55 public static void exit(Log log, String methodName, Object result) 56 { 57 StringBuffer buffer = new StringBuffer (BUFFER_SIZE); 58 59 buffer.append("END "); 60 buffer.append(methodName); 61 buffer.append("() ["); 62 63 convert(buffer, result); 64 65 buffer.append("]"); 66 67 log.debug(buffer.toString()); 68 } 69 70 public static void voidExit(Log log, String methodName) 71 { 72 StringBuffer buffer = new StringBuffer (BUFFER_SIZE); 73 74 buffer.append("END "); 75 buffer.append(methodName); 76 buffer.append("()"); 77 78 log.debug(buffer.toString()); 79 } 80 81 public static void exception(Log log, String methodName, Throwable t) 82 { 83 StringBuffer buffer = new StringBuffer (BUFFER_SIZE); 84 85 buffer.append("EXCEPTION "); 86 buffer.append(methodName); 87 buffer.append("() -- "); 88 89 buffer.append(t.getClass().getName()); 90 91 log.debug(buffer.toString(), t); 92 } 93 94 public static void convert(StringBuffer buffer, Object input) 95 { 96 if (input == null) 97 { 98 buffer.append("<null>"); 99 return; 100 } 101 102 106 if (!(input instanceof Object [])) 107 { 108 buffer.append(input.toString()); 109 return; 110 } 111 112 buffer.append("("); 113 buffer.append(ClassFabUtils.getJavaClassName(input.getClass())); 114 buffer.append("){"); 115 116 Object [] array = (Object []) input; 117 int count = array.length; 118 119 for (int i = 0; i < count; i++) 120 { 121 if (i > 0) 122 buffer.append(", "); 123 124 convert(buffer, array[i]); 127 } 128 129 buffer.append("}"); 130 } 131 } | Popular Tags |