1 57 58 package org.logicalcobwebs.logging.impl; 59 60 import org.apache.log4j.Category; 61 import org.logicalcobwebs.logging.Log; 62 import org.logicalcobwebs.logging.LogConfigurationException; 63 import org.logicalcobwebs.logging.LogFactory; 64 65 import java.util.Enumeration ; 66 import java.util.Hashtable ; 67 import java.util.Vector ; 68 69 74 public final class Log4jFactory extends LogFactory { 75 76 public Log4jFactory () { 77 super (); 78 } 79 80 83 private Hashtable attributes = new Hashtable (); 84 85 private Hashtable instances = new Hashtable (); 87 88 90 96 public Object getAttribute (String name) { 97 return (attributes.get (name)); 98 } 99 100 105 public String [] getAttributeNames () { 106 Vector names = new Vector (); 107 Enumeration keys = attributes.keys (); 108 while (keys.hasMoreElements ()) { 109 names.addElement (keys.nextElement ()); 110 } 111 String results[] = new String [names.size ()]; 112 for (int i = 0; i < results.length; i++) { 113 results[i] = (String ) names.elementAt (i); 114 } 115 return (results); 116 } 117 118 127 public Log getInstance (Class clazz) 128 throws LogConfigurationException { 129 Log instance = (Log) instances.get (clazz); 130 if (instance != null) { 131 return instance; 132 } 133 134 instance = new Log4JCategoryLog (Category.getInstance (clazz)); 135 instances.put (clazz, instance); 136 return instance; 137 } 138 139 public Log getInstance (String name) 140 throws LogConfigurationException { 141 Log instance = (Log) instances.get (name); 142 if (instance != null) { 143 return instance; 144 } 145 146 147 instance = new Log4JCategoryLog (Category.getInstance (name)); 148 instances.put (name, instance); 149 return instance; 150 } 151 152 159 public void release () { 160 161 instances.clear (); 162 163 } 165 166 172 public void removeAttribute (String name) { 173 attributes.remove (name); 174 } 175 176 185 public void setAttribute (String name, Object value) { 186 if (value == null) { 187 attributes.remove (name); 188 } else { 189 attributes.put (name, value); 190 } 191 } 192 193 } 194 195 | Popular Tags |